At 05:47 PM 10/15/2001 +1100, you wrote:
>Hi.
>
>I am new to XML and xerces. I am hoping that someone can explain to me
>why code segment 1 prints #text and then seg faults, but code segment 2
>(also below) prints the lines:
> tag2
> 21 text
>as expected?
>
>The xml file is:
>
><root>
> <tag1>
> <tag11>11 text</tag11>
> <tag12>12 text</tag12>
> </tag1>
>
> <tag2>
> <tag21>21 text</tag21>
> <tag22>22 text</tag22>
> </tag2>
></root>
>
>
>Code segment 1
>---------------
> DOM_Document doc = parser.getDocument();
> DOM_Element rootElement = doc.getDocumentElement();
> DOMString tag2Name = DOMString("tag2");
> DOM_NodeList nodeList = rootElement.getElementsByTagName(tag2Name);
> DOM_Node node2 = nodeList.item(0);
> DOM_Node node21 = node2.getFirstChild();
> node21.getNodeName().println();
It writes #text because here you are printing the name of the tag that is
the first child of tag2 (and it's the text node between tag2 and tag21)
> node21.getFirstChild().getNodeValue().println();
And it crashes here because you are asking for the first child of a text
node (and you get a null object).
You need to replace the getFirstChild with a loop that looks for element
nodes, skipping whitespace-only text nodes
Alberto
-------------------------------
Alberto Massari
eXcelon Corp.
http://www.StylusStudio.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]