xmldb api and namespace handling

Friday, 25 March 2011 · 5 messages · last reply 26 Mar 2011
F
frans25 Mar 2011 00:01 #
I'am accessing BaseX 6.5.1 through the XMLDB API. There are some issues with namespace handling when storing resources. Let me clarify that with some examples. First example I want to store the following as a resource: String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + "<tag xmlns=\"http://example.org\">" + "</tag>"; This yields <tag xmlns="http://example.org"/> in the GUI. So this is OK. Second example I want to store the following as a resource and INTPARSE = false: String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + "<tns:tag xmlns:tns=\"http://example.org\">" + "</tns:tag>"; This yields the following exception: org.xmldb.api.base.XMLDBException: "null" (Line 1): The prefix "tns" for element "tns:tag" is not bound Third example I want to store the following as a resource and INTPARSE = true: String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + "<tns:tag xmlns:tns=\"http://example.org\">" + "</tns:tag>"; This yields <tns:tag xmlnstns="http://example.org"/> in the GUI. The colon is missing in ' xmlnstns' . So this is not OK. Are the second and third examples bugs or should I change some setting to get a proper handling of namespaces? Regards, Frans
AW
Andreas Weiler25 Mar 2011 08:34 #
Hi Frans, could you send me your java class, so i can have a look at it. -- Andreas
Quoted text · frans · 42 lines
Am 25.03.2011 um 00:01 schrieb frans@planet: > I'am accessing BaseX 6.5.1 through the XMLDB API. There are some issues with namespace handling when storing resources. Let me clarify that with some examples. > > First example > > I want to store the following as a resource: > > String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + > "<tag xmlns=\"http://example.org\">" + > "</tag>"; > > This yields <tag xmlns="http://example.org"/> in the GUI. So this is OK. > > Second example > > I want to store the following as a resource and INTPARSE = false: > > String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + > "<tns:tag xmlns:tns=\"http://example.org\">" + > "</tns:tag>"; > > This yields the following exception: > org.xmldb.api.base.XMLDBException: "null" (Line 1): The prefix "tns" for element "tns:tag" is not bound > > Third example > > I want to store the following as a resource and INTPARSE = true: > > String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + > "<tns:tag xmlns:tns=\"http://example.org\">" + > "</tns:tag>"; > > This yields <tns:tag xmlnstns="http://example.org"/> in the GUI. The colon is missing in ' xmlnstns' . So this is not OK. > > Are the second and third examples bugs or should I change some setting to get a proper handling of namespaces? > > Regards, > Frans > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
AW
Andreas Weiler25 Mar 2011 09:37 #
Hi Frans, the following code with the newest release of BaseX produces correct results: package org.basex.examples.xmldb;
import org.basex.api.xmldb.BXCollection;
import org.xmldb.api.base.*;
import org.xmldb.api.modules.XMLResource;
import org.xmldb.api.*;
/** * This class serves as an example for creating a database with the XML:DB API. * * @author BaseX Team 2005-11, BSD License */ public final class Test { /** Database driver. */ public static final String DRIVER = "org.basex.api.xmldb.BXDatabase"; /** * Main method of the example class. * @param args (ignored) command-line arguments * @throws Exception exception */ public static void main(final String[] args) throws Exception { System.out.println("=== XMLDBCreate ===");
    try {
      // Register the database
      Class<?> c = Class.forName(DRIVER);
      Database db = (Database) c.newInstance();
      DatabaseManager.registerDatabase(db);
System.out.println("\n* Create a new collection.");
      // Create a new collection
      BXCollection col = new BXCollection("Collection", false);

      // ID for the first document
      String id1 = "doc1";
      // Content of the first document
      String doc1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
      "<tag xmlns=\"http://example.org\">" +
      "</tag>";

      // ID for the second document
      String id2 = "doc2";
      // Content of the second document
      String doc2 = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
      "<tns:tag xmlns:tns=\"http://example.org\">" +
      "</tns:tag>";
System.out.println("\n* Create new resources.");
      // Create a new XML resource with the specified ID
      XMLResource res1 = col.createResource(id1, XMLResource.RESOURCE_TYPE);
      XMLResource res2 = col.createResource(id2, XMLResource.RESOURCE_TYPE);

      // Set the content of the XML resource as the document
      res1.setContent(doc1);
      res2.setContent(doc2);
System.out.println("\n* Store new resource.");
      // Store the resource into the database
      col.storeResource(res1);
      col.storeResource(res2);
col.close();
    } catch(final XMLDBException ex) {
      // Handle exceptions
      System.err.println("XML:DB Exception occured " + ex.errorCode);
    }
  }
}
-- Andreas
Quoted text · Andreas Weiler · 55 lines
Am 25.03.2011 um 08:34 schrieb Andreas Weiler: > Hi Frans, > > could you send me your java class, so i can have a look at it. > > -- Andreas > > Am 25.03.2011 um 00:01 schrieb frans@planet: > >> I'am accessing BaseX 6.5.1 through the XMLDB API. There are some issues with namespace handling when storing resources. Let me clarify that with some examples. >> >> First example >> >> I want to store the following as a resource: >> >> String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + >> "<tag xmlns=\"http://example.org\">" + >> "</tag>"; >> >> This yields <tag xmlns="http://example.org"/> in the GUI. So this is OK. >> >> Second example >> >> I want to store the following as a resource and INTPARSE = false: >> >> String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + >> "<tns:tag xmlns:tns=\"http://example.org\">" + >> "</tns:tag>"; >> >> This yields the following exception: >> org.xmldb.api.base.XMLDBException: "null" (Line 1): The prefix "tns" for element "tns:tag" is not bound >> >> Third example >> >> I want to store the following as a resource and INTPARSE = true: >> >> String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + >> "<tns:tag xmlns:tns=\"http://example.org\">" + >> "</tns:tag>"; >> >> This yields <tns:tag xmlnstns="http://example.org"/> in the GUI. The colon is missing in ' xmlnstns' . So this is not OK. >> >> Are the second and third examples bugs or should I change some setting to get a proper handling of namespaces? >> >> Regards, >> Frans >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
F
frans26 Mar 2011 17:53 #
Hi Andreas, Thanks for your answer. I added some cases to your Test-class and I ran it against the newest release of BaseX (6.6). setContent and setContentAsDOM work fine. setContentAsSax works fine for <tag xmlns=\"http://example.org\"/>. For <tns:tag xmlns:tns=\"http://example.org\"/> setContentAsSax gives <tns:tag xmlnstns="http://example.org"/>. The colon is missing in xmlnstns. Regards, Frans Op 25 mrt 2011, om 09:37 heeft Andreas Weiler het volgende geschreven:
Quoted text · Andreas Weiler · 138 lines
> Hi Frans, > > the following code with the newest release of BaseX produces correct results: > > package org.basex.examples.xmldb; > > import org.basex.api.xmldb.BXCollection; > import org.xmldb.api.base.*; > import org.xmldb.api.modules.XMLResource; > import org.xmldb.api.*; > > /** > * This class serves as an example for creating a database with the XML:DB API. > * > * @author BaseX Team 2005-11, BSD License > */ > public final class Test { > /** Database driver. */ > public static final String DRIVER = "org.basex.api.xmldb.BXDatabase"; > > /** > * Main method of the example class. > * @param args (ignored) command-line arguments > * @throws Exception exception > */ > public static void main(final String[] args) throws Exception { > > System.out.println("=== XMLDBCreate ==="); > > try { > // Register the database > Class<?> c = Class.forName(DRIVER); > Database db = (Database) c.newInstance(); > DatabaseManager.registerDatabase(db); > > System.out.println("\n* Create a new collection."); > > // Create a new collection > BXCollection col = new BXCollection("Collection", false); > > // ID for the first document > String id1 = "doc1"; > // Content of the first document > String doc1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + > "<tag xmlns=\"http://example.org\">" + > "</tag>"; > > // ID for the second document > String id2 = "doc2"; > // Content of the second document > String doc2 = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + > "<tns:tag xmlns:tns=\"http://example.org\">" + > "</tns:tag>"; > > System.out.println("\n* Create new resources."); > > // Create a new XML resource with the specified ID > XMLResource res1 = col.createResource(id1, XMLResource.RESOURCE_TYPE); > XMLResource res2 = col.createResource(id2, XMLResource.RESOURCE_TYPE); > > // Set the content of the XML resource as the document > res1.setContent(doc1); > res2.setContent(doc2); > > System.out.println("\n* Store new resource."); > > // Store the resource into the database > col.storeResource(res1); > col.storeResource(res2); > > col.close(); > > } catch(final XMLDBException ex) { > // Handle exceptions > System.err.println("XML:DB Exception occured " + ex.errorCode); > } > } > } > > -- Andreas > > Am 25.03.2011 um 08:34 schrieb Andreas Weiler: > >> Hi Frans, >> >> could you send me your java class, so i can have a look at it. >> >> -- Andreas >> >> Am 25.03.2011 um 00:01 schrieb frans@planet: >> >>> I'am accessing BaseX 6.5.1 through the XMLDB API. There are some issues with namespace handling when storing resources. Let me clarify that with some examples. >>> >>> First example >>> >>> I want to store the following as a resource: >>> >>> String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + >>> "<tag xmlns=\"http://example.org\">" + >>> "</tag>"; >>> >>> This yields <tag xmlns="http://example.org"/> in the GUI. So this is OK. >>> >>> Second example >>> >>> I want to store the following as a resource and INTPARSE = false: >>> >>> String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + >>> "<tns:tag xmlns:tns=\"http://example.org\">" + >>> "</tns:tag>"; >>> >>> This yields the following exception: >>> org.xmldb.api.base.XMLDBException: "null" (Line 1): The prefix "tns" for element "tns:tag" is not bound >>> >>> Third example >>> >>> I want to store the following as a resource and INTPARSE = true: >>> >>> String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + >>> "<tns:tag xmlns:tns=\"http://example.org\">" + >>> "</tns:tag>"; >>> >>> This yields <tns:tag xmlnstns="http://example.org"/> in the GUI. The colon is missing in ' xmlnstns' . So this is not OK. >>> >>> Are the second and third examples bugs or should I change some setting to get a proper handling of namespaces? >>> >>> Regards, >>> Frans >>> _______________________________________________ >>> BaseX-Talk mailing list >>> BaseX-Talk at mailman.uni-konstanz.de >>> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
AW
Andreas Weiler26 Mar 2011 18:31 #
Hi Frans, thanks for your further tests, we will have a look at that issue. Kind regards, Andreas
Quoted text · frans · 155 lines
Am 26.03.2011 um 17:53 schrieb frans@planet: > Hi Andreas, > > Thanks for your answer. I added some cases to your Test-class and I ran it against the newest release of BaseX (6.6). > > > <Test.java> > > setContent and setContentAsDOM work fine. setContentAsSax works fine for <tag xmlns=\"http://example.org\"/>. > For <tns:tag xmlns:tns=\"http://example.org\"/> setContentAsSax gives <tns:tag xmlnstns="http://example.org"/>. The colon is missing in xmlnstns. > > Regards, > Frans > > Op 25 mrt 2011, om 09:37 heeft Andreas Weiler het volgende geschreven: > >> Hi Frans, >> >> the following code with the newest release of BaseX produces correct results: >> >> package org.basex.examples.xmldb; >> >> import org.basex.api.xmldb.BXCollection; >> import org.xmldb.api.base.*; >> import org.xmldb.api.modules.XMLResource; >> import org.xmldb.api.*; >> >> /** >> * This class serves as an example for creating a database with the XML:DB API. >> * >> * @author BaseX Team 2005-11, BSD License >> */ >> public final class Test { >> /** Database driver. */ >> public static final String DRIVER = "org.basex.api.xmldb.BXDatabase"; >> >> /** >> * Main method of the example class. >> * @param args (ignored) command-line arguments >> * @throws Exception exception >> */ >> public static void main(final String[] args) throws Exception { >> >> System.out.println("=== XMLDBCreate ==="); >> >> try { >> // Register the database >> Class<?> c = Class.forName(DRIVER); >> Database db = (Database) c.newInstance(); >> DatabaseManager.registerDatabase(db); >> >> System.out.println("\n* Create a new collection."); >> >> // Create a new collection >> BXCollection col = new BXCollection("Collection", false); >> >> // ID for the first document >> String id1 = "doc1"; >> // Content of the first document >> String doc1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + >> "<tag xmlns=\"http://example.org\">" + >> "</tag>"; >> >> // ID for the second document >> String id2 = "doc2"; >> // Content of the second document >> String doc2 = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + >> "<tns:tag xmlns:tns=\"http://example.org\">" + >> "</tns:tag>"; >> >> System.out.println("\n* Create new resources."); >> >> // Create a new XML resource with the specified ID >> XMLResource res1 = col.createResource(id1, XMLResource.RESOURCE_TYPE); >> XMLResource res2 = col.createResource(id2, XMLResource.RESOURCE_TYPE); >> >> // Set the content of the XML resource as the document >> res1.setContent(doc1); >> res2.setContent(doc2); >> >> System.out.println("\n* Store new resource."); >> >> // Store the resource into the database >> col.storeResource(res1); >> col.storeResource(res2); >> >> col.close(); >> >> } catch(final XMLDBException ex) { >> // Handle exceptions >> System.err.println("XML:DB Exception occured " + ex.errorCode); >> } >> } >> } >> >> -- Andreas >> >> Am 25.03.2011 um 08:34 schrieb Andreas Weiler: >> >>> Hi Frans, >>> >>> could you send me your java class, so i can have a look at it. >>> >>> -- Andreas >>> >>> Am 25.03.2011 um 00:01 schrieb frans@planet: >>> >>>> I'am accessing BaseX 6.5.1 through the XMLDB API. There are some issues with namespace handling when storing resources. Let me clarify that with some examples. >>>> >>>> First example >>>> >>>> I want to store the following as a resource: >>>> >>>> String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + >>>> "<tag xmlns=\"http://example.org\">" + >>>> "</tag>"; >>>> >>>> This yields <tag xmlns="http://example.org"/> in the GUI. So this is OK. >>>> >>>> Second example >>>> >>>> I want to store the following as a resource and INTPARSE = false: >>>> >>>> String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + >>>> "<tns:tag xmlns:tns=\"http://example.org\">" + >>>> "</tns:tag>"; >>>> >>>> This yields the following exception: >>>> org.xmldb.api.base.XMLDBException: "null" (Line 1): The prefix "tns" for element "tns:tag" is not bound >>>> >>>> Third example >>>> >>>> I want to store the following as a resource and INTPARSE = true: >>>> >>>> String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + >>>> "<tns:tag xmlns:tns=\"http://example.org\">" + >>>> "</tns:tag>"; >>>> >>>> This yields <tns:tag xmlnstns="http://example.org"/> in the GUI. The colon is missing in ' xmlnstns' . So this is not OK. >>>> >>>> Are the second and third examples bugs or should I change some setting to get a proper handling of namespaces? >>>> >>>> Regards, >>>> Frans >>>> _______________________________________________ >>>> BaseX-Talk mailing list >>>> BaseX-Talk at mailman.uni-konstanz.de >>>> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>> >>> _______________________________________________ >>> BaseX-Talk mailing list >>> BaseX-Talk at mailman.uni-konstanz.de >>> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> >

⚡Generated with XQuery