Hello, I have inserted a comment in the code.
Gareth Reakes, Lead Software Engineer
DecisionSoft Ltd. http://www.decisionsoft.com
Office: +44 (0) 1865 203192
On Sat, 24 Mar 2001, Williams Roger wrote:
> Hi
>
> I am trying to step through the subnodes of a parent node. I have lots of
> problems.
>
> The first primary problem is that I cannot get the getNextSibling member
> function to work. I can get to the first child(propone), but i cannot get to
> the second one by doing a getNextSibling. I have simplified the code
> snippet.
>
> xmldoc(I took out all unnec spaces) looks like:
> <root><properties><propone></propone><proptwo></proptwo></properties></root>
>
> simplified code:
> DOMParser Parser;
> Parser.parse(*memBufIS); //option1:use membuf
> //Parser.parse("c:/myxml.xml"); //option2:use file
> Parser.setDoNamespaces(true);
> DOM_Document DomDoc = Parser.getDocument();
> DOM_NodeList NdLsPropTags =
> DomDoc.getElementsByTagName("properties");
> int nPropTags;
> if ((nPropTags = NdLsPropTags.getLength())!=1) {
> if (nPropTags==0) {
> printf("No properties tag");
> }
> else {
> printf("More than one properties tag");
> }
> return false;
> }
> printf("\nPropTags\t%d\n",nPropTags);
>
> DOMString dsNdNmProp,dsNdVlProp,dsNdNmNode,dsNdVlNode;
> char
> *pszNdNmProp=NULL,*pszNdVlProp=NULL,*pszNdNmNode=NULL,*pszNdVlNode=NULL;
> int nNdTpProp,nNdTpNode,i=0;
>
> DOM_Node NdProp = NdLsPropTags.item(0);
>
> nNdTpProp=NdProp.getNodeType();
> dsNdNmProp=NdProp.getNodeName();
> pszNdNmProp = dsNdNmProp.transcode();
> dsNdVlProp = NdProp.getNodeValue();
> if (pszNdVlProp==NULL)
> pszNdVlProp="NULL";
>
> printf("\n\t%d\t%s\t%s\n",nNdTpProp,pszNdNmProp,pszNdVlProp);
>
> if (!NdProp.hasChildNodes())
> return false;
> DOM_Node NdNode;
>
> NdNode = NdProp.getFirstChild();
> if (NdNode.isNull())
> return true;
> nNdTpNode = NdNode.getNodeType();
> dsNdNmNode=NdNode.getNodeName();
> pszNdNmNode = dsNdNmNode.transcode();
> dsNdVlNode=NdNode.getNodeValue();
> pszNdVlNode = dsNdVlNode.transcode();
Remember to delete these char*. Look at the DOMSerialize example for how
to print DOMStrings.
> if (pszNdVlNode==NULL)
> pszNdVlNode="NULL";
>
> printf("\n%d\t%d\t%s\t\t<%s>\n",i,nNdTpNode,pszNdNmNode,pszNdVlNode);
>
> i++;
> NdNode = NdProp.getNextSibling();
Here you are asking for the sibling of NdProp. NdProp is the properties
tag. Instead you should write NdNode = NdNode.getNextSibling.
> if (NdNode.isNull()) //turns out to be true
> return true; //ie no next sibling, cannot get
> proptwo
> nNdTpNode = NdNode.getNodeType();
> dsNdNmNode=NdNode.getNodeName();
> pszNdNmNode = dsNdNmNode.transcode();
> dsNdVlNode=NdNode.getNodeValue();
> pszNdVlNode = dsNdVlNode.transcode();
> if (pszNdVlNode==NULL)
> pszNdVlNode="NULL";
>
> printf("\n%d\t%d\t%s\t\t<%s>\n",i,nNdTpNode,pszNdNmNode,pszNdVlNode);
>
> i++;
> NdNode = NdProp.getNextSibling();
> if (NdNode.isNull())
> return true;
> nNdTpNode = NdNode.getNodeType();
> dsNdNmNode=NdNode.getNodeName();
> pszNdNmNode = dsNdNmNode.transcode();
> dsNdVlNode=NdNode.getNodeValue();
> pszNdVlNode = dsNdVlNode.transcode();
> if (pszNdVlNode==NULL)
> pszNdVlNode="NULL";
>
> printf("\n%d\t%d\t%s\t\t<%s>\n",i,nNdTpNode,pszNdNmNode,pszNdVlNode);
>
>
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: 23 March 2001 11:48 PM
> To: [EMAIL PROTECTED]
> Subject: Re: NEWBIE:Cannot get to subnodes using getFirstChild and
> getNextSibl ing
>
>
>
> >Is there a way of getting pass these type of characters like Tabs,
> >Linefeeds,etc etc.
>
> Advance to the next sibling node.
>
> >It would appear that the getNextSibling() function points to the same
> >element(most prolly a LineFeed+tab) everytime.
>
> You mean node rather than element. But to answer your question, consider
> the following pseudocode:
>
> Element myProperties=myDoc.getElementByTagName("properties");
> for(Node child=myProperties.getFirstChild;
> child!=null;
> child=child.getNextSibling() )
> {
> if (child.getNodeType()==Node.ELEMENT_NODE)
> {
> // Do whatever's appropriate
> }
> else
> {
> // In your application, you may not care about anything
> else.
> // If that's true, just ignore it and move on
> }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]