Here's the deal: I'm using a DOM tree to store data of my app. Eventually I will add load and save code.
I've got a weird problem though. The DTD of my DOM contains this:
I've tried three methods of creating the DOM Document, first only in memory via the DOMImplementation, second by "loading" a fixed string a passing a system identifier and third by loading an empty XML file:Code:<!ENTITY % stdatt "id ID #REQUIRED title CDATA #REQUIRED"> <!ELEMENT data (topic?)> <!ATTLIST data xmlns CDATA #FIXED "http://www.cornedbee.com/jknowledger/storage/pure-memory"> <!ELEMENT topic (position, ((topic | content)*))> <!ATTLIST topic %stdatt;>
Code:<?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE data SYSTEM "../dtd/data.dtd"> <data xmlns="http://www.cornedbee.com/jknowledger/storage/pure-memory" />The parser is validating and doesn't give any errors.Code:try { DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance(); fac.setValidating(true); DocumentBuilder db = fac.newDocumentBuilder(); doc = db.parse(new File("resources/PureMemInitial.xml"));
Then I go ahead and create a root topic element:
I append this new element to the document element and let it rest.Code:Element docElem = doc.getDocumentElement(); Element root = doc.createElementNS(nmsp, "topic"); root.setAttribute("title", "Root"); root.setAttribute("id", ID.generate().toString());
I have also tried using a plain createElement without the namespace.
Later in the code I use getElementById to get the element. I KNOW that the id is correct, however the function always returns null.
I'm using a 1.4.2 JDK.
Does anyone have an idea why it doesn't work? It seems to me that id is not recognized as an ID, but I don't know why.
Thx in advance.


CornedBee
Reply With Quote