Your XML file actually looks like this in a DOM tree.

Relation - ELEMENTNODE
  Whitespace - TEXTNODE
  Subtype - ELEMENTNODE
  Whitespace - TEXTNODE

The endlines in your document is stored inside the DOM tree as well. You
can filter them out using a DOMTreeWalker.

Regards
/ Erik

> -----Original Message-----
> From: Song Li [mailto:[EMAIL PROTECTED]
> Sent: den 3 juni 2004 17:03
> To: [EMAIL PROTECTED]
> Subject: Newbie's question -- extracting information from XML file
> 
> Hi,
> 
> I have an XML file with the format looks like:
> ===================================
>   <relation entry1="43" entry2="48" type="ECrel">
>          <subtype name="compound" value="88"/>
>      </relation>
> ===================================
> 
> I want to extract the "value" under the node "subtype" by using DOM,
> I've tried two methods but neither return a correct result:
> 
> method 1:  get a DOMnode(let's call it nd)  points to "relation", then
> call "nd2 = nd->getFirstChild();". The problem is  that this nd2 has
> the type "TEXT NODE", so I can't use "getAttributes", and
> getTextContent() doesn't work as well.
> 
> method2:
> subList = doc->getElementsByTagName(XMLString::transcode("subtype"));
> 
> This time subList->item(0) has the type "ELEMENT NODE", but
> surprisingly "subList->item(0)->getAttributes()->getLength()" returns
1
> !!! and this only attribute is "name" ... I still cannot extract
> "value".
> 
> So what's wrong with these methods and what's the good way to get
> "value" from this file???
> 
> Thanks a lot! Please reply, if this message is not clear enough I can
> post my code in more detail......
> 
> Song
> 
> 
> ---------------------------------------------------------------------
> 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]

Reply via email to