You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Christopher Zanelli/NYT/NYTIMES <za...@nytimes.com> on 2001/10/02 22:15:49 UTC
Hierarchy request error, don't know why!
OK, I'm running into what seems to be a poorly documented quirk for
DocumentBuilder.
Using the document builder, I am parsing out and XML file, which is never
more than 1 element deep with attributes.
However, after I set all the attribute values, I need to create extra
elements and append them to the document. When I use the appendChild
method, the Hierarchy request error is coming up. Here's a brief example:
*********
Document walgreensXMLInvoice = null;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
walgreensXMLInvoice = builder.parse(Constants.PATHTOWALGREENSTEMPLATE);
fHasBeenInitialized = true;
load();
}
catch .....
....... // Just set the values of all the other attributes by sequentially going through the nodes...
for (int i = 0; i < itemList.size; i++) {
Element item = walgreensXMLInvoice.createElement("Item");
item.setAttribute("LineNumber", (new Integer(i+1)).toString());
item.setAttribute("Quantity", (new Integer(itemList[i].quantity)).toString());
item.setAttribute("ItemDescription", itemList[i].itemDescription);
item.setAttribute("BIPAD", itemList[i].bipad);
item.setAttribute("UnitPrice", (new Double(itemList[i].unitPrice)).toString());
walgreensXMLInvoice.appendChild(item); // Blows up here!
// I tried this too
// walgreensXMLInvoice.adoptNode(item); ---- No error, but never adds the node to the document.
}
*********
Debugger Stack Trace Report:
Thread[main,5,main] (Alive)
Uncaught exception (org.w3c.dom.DOMException: DOM006 Hierarchy request error)
DeferredDocumentImpl(CoreDocumentImpl).insertBefore(Node, Node)
this=(org.apache.xerces.dom.DeferredDocumentImpl) [#document: null]
arg_1=(org.w3c.dom.Node) [Item2: null]
arg_2=(org.w3c.dom.Node) null
DeferredDocumentImpl(NodeImpl).appendChild(Node)
this=(org.apache.xerces.dom.DeferredDocumentImpl) [#document: null]
arg_1=(org.w3c.dom.Node) [Item2: null]
WalgreensInvoice.setLineItems()
this=(com.cs.invoiceapp.busobj.WalgreensInvoice) com.cs.invoiceapp.busobj.WalgreensInvoice@347e
workingNode=(org.w3c.dom.Node) [Item: null]
i=(int) 1
item=(org.w3c.dom.Element) [Item2: null]
WalgreensInvoice.getInvoiceDocument()
this=(com.cs.invoiceapp.busobj.WalgreensInvoice) com.cs.invoiceapp.busobj.WalgreensInvoice@347e
WalgreensInvoice.main(String [])
args=([Ljava.lang.String;) [Ljava.lang.String;@220e
newInvoice=(com.cs.invoiceapp.busobj.WalgreensInvoice) com.cs.invoiceapp.busobj.WalgreensInvoice@347e
doc=(org.w3c.dom.Document) null
trans=(com.cs.invoiceapp.util.transformer.DocToStringTransformer) com.cs.invoiceapp.util.transformer.DocToStringTransformer@57de