Altova Mailing List Archives


Re: IXMLDOMNode Question?

From: "Gustavo Cardona Ramirez" <gustavo.cardona@----------.--->
To: NULL
Date: 7/19/2004 9:57:00 AM
Thank you for your help "it is very clear your answer :-)".

> the result displayed is
>    direct text child 1.direct text child 2.

A question more,  if, I only  wanted to extract the value >>direct text
child 1.<<  using  the DOM, ¿What I should done?

Thank you again.

Gustavo.

"Martin Honnen" <mahotrash@y...> escribió en el mensaje
news:eX6GbvZbEHA.3664@T......
>
>
> Gustavo Cardona Ramirez wrote:
>
> > I am decomposing the XML dynamically and I ignore the elements and the
depth
> > of the document XML (See example next)
>
> It is not quite clear what you want but Han guessed that if you have for
> instance the XML
>    <element>direct text child 1.<child-element>nested text child
> 1.</child-element>direct text child 2.</element>
> that you then only want to extract the text content of text child nodes.
> He then made a suggestion on how to do that with XPath, if you don't
> want to use XPath but simply the DOM then the following function
> (JScript example) could help
>
> function getTextChildrenContent (elementNode) {
>    var text = '';
>    for (var i = 0; i < elementNode.childNodes.length; i++) {
>      var childNode = elementNode.childNodes[i];
>      if (childNode.nodeType === 3) {
>        text += childNode.nodeValue;
>      }
>    }
>    return text;
> }
>
> Used in the following example
>
> var xmlDocument = new ActiveXObject('Msxml2.DOMDocument.4.0');
> xmlDocument.async = false;
>
> var xmlString = '';
> xmlString += '<root>' +
>    '<element>direct text child 1.<child-element>nested text child
> 1.</child-element>direct text child 2.</element>' +
>    '</root>';
> var loaded = xmlDocument.loadXML(xmlString);
>
> var element = xmlDocument.getElementsByTagName('element')[0];
>
> var text = getTextChildrenContent(element);
>
> alert(text)
>
> the result displayed is
>    direct text child 1.direct text child 2.
>
> -- 
>
> Martin Honnen
> http://JavaScript.FAQTs.com/
>


Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.