What you are doing looks basically correct to me. The first element added
to the document implictly becomes the root element, then you are adding
other elements underneath that. It seems basically correct. One thing to
try, assuming that you are confident that your build is ok since you can
run the standard samples, is to replace your programmatic code by a quick
parse of a file with the same content and try to print that. If that
croaks, maybe your version of the printing code is not happy. If it does,
then perhaps you can compare the resulting tree and see how it differs from
your tree.
Unfortunately Andy, who wrote the DOM stuff, is in a long W3C meeting, so
he is kind of incommunicado (sp?) until probably friday. So it might be
then before you get a definitive answer to this.
----------------------------------------
Dean Roddey
Software Weenie
IBM Center for Java Technology - Silicon Valley
[EMAIL PROTECTED]
Steve Kotsopoulos <[EMAIL PROTECTED]> on 01/24/2000 12:30:48 PM
Please respond to [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
cc:
Subject: Segmentation fault when parsing Document created from scratch
I'm using Xerces-C version 1.0.1 15-Dec-99 under RedHat Linux 6.1
with g++ (egcs-2.91.66).
I'm trying to build documents by hand, not by reading an XML file.
I haven't been able to find any examples of the correct way of doing this,
but here's what I have right now:
DOM_Document doc = DOM_Document::createDocument();
DOM_Element del = doc.createElement(DOMString("name"));
DOM_Element tag1 = doc.createElement(DOMString("foo"));
DOM_Text val1 = doc.createTextNode(DOMString("bar"));
doc.appendChild(del);
del.appendChild(tag1);
tag1.appendChild(val1);
The idea is to build an XML document something like this:
<name>
<foo>bar</foo>
</name>
When I create a document with the above, and then pass it to code
based on the DOMPrint parsing example, I'm seeing a segmentation fault
in DOM_Node::getNodeName() of libxerces-c1_0.so
when my parsing code starts with:
char *nname = node.getNodeName().transcode();
char *nvalue = node.getNodeValue().transcode();
I suspect that I might not be building my document correctly,
is this the case? If so, what is the correct way to do it?
Thanks
Steve