You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Williams Roger <RW...@OLDMUTUAL.com> on 2001/03/23 17:57:39 UTC
NEWBIE:Cannot get to subnode using getFirstChild
I need help
I am trying to walk through all the ChildNodes in a Node.
I can get to the ParentNode(properties) by using getElementsByTag, but i
can't seem to get a Node representation of the first child(propone) of the
ParantNode(properties).
My XML Document looks like:
<?xml version='1.0' encoding='ascii'?>
<root>
<surname>abcdef</surname>
<properties>
<propone>aaaa</propone>
<proptwo>bbbb</proptwo>
</properties>
</root>
code snippet:
Parser.parse("c:/myxml.xml"); //option2:use file
DOM_Document DomDoc = Parser.getDocument();
DOM_NodeList NodeList =
DomDoc.getElementsByTagName("properties");
int nElmts = NodeList.getLength();
printf("\nnElmts\t%d\n",nElmts);
DOM_Node Node = NodeList.item(0);
if (Node.isNull())
return 0;
unsigned int ln = 0;
ln = NodeList.getLength();
short NodeType = 0;
NodeType = Node.getNodeType();
DOMString dsVal0=Node.getNodeName();
int ln0 = dsVal0.length();
char *szVal0 = dsVal0.transcode();
cout<<"\nNodeName of properties Node: "<<szVal0<<"\n";
DOM_Node SubNode = Node.getFirstChild();
DOMString dsVal1=SubNode.getNodeName();
int ln1 = dsVal1.length();
char *szVal1 = dsVal1.transcode();
cout<<"\nNodeName of first property Node: "<<szVal1<<"\n";
Problem two
How do I get a list of all the nodes which are only one level under a
parentnode? If I do a ParentNode.getChildNodes, I get all the Nodes
including the ones which lies deeper than the nodes directly under the
parentnode.
from
Rog
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: NEWBIE:Cannot get to subnode using getFirstChild
Posted by Bill Schindler <bi...@bitranch.com>.
On Friday, March 23, 2001, at 09:57 AM, Williams Roger wrote:
> <properties>
> <propone>aaaa</propone>
> <proptwo>bbbb</proptwo>
> </properties>
If you checked the type of the first node of <properties> you would
discover that it is not an element node. The DOM tree that's created
from your XML above would produce something like:
ELEMENT: properties
TEXT: a line-feed and several spaces
ELEMENT: propone
TEXT: aaaa
ELEMENT: proptwo
TEXT: bbbb
TEXT: a line-feed and several spaces
In other words, the first child of <properties> isn't an element. If you
want the first element node, you'll need to walk through the child nodes
until you find an element node.
--Bill
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
RE: NEWBIE:Cannot get to subnode using getFirstChild
Posted by "David E. Cleary" <da...@progress.com>.
> I need help
>
> I am trying to walk through all the ChildNodes in a Node.
> I can get to the ParentNode(properties) by using getElementsByTag, but i
> can't seem to get a Node representation of the first child(propone) of the
> ParantNode(properties).
>
> My XML Document looks like:
> <?xml version='1.0' encoding='ascii'?>
> <root>
> <surname>abcdef</surname>
> <properties>
> <propone>aaaa</propone>
> <proptwo>bbbb</proptwo>
> </properties>
> </root>
The first child is a text node that contains an LF and space or tab
characters. The second child is propone.
> Problem two
> How do I get a list of all the nodes which are only one level under a
> parentnode? If I do a ParentNode.getChildNodes, I get all the Nodes
> including the ones which lies deeper than the nodes directly under the
> parentnode.
No you don't. You get just the children of that node, which include text
nodes as well as element nodes.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org