Error getting inner text from XML node using JavaScript

I am reading an XML document using JavaScript and jQuery, and you need to extract some text from node to save to an array. The XML structure is as follows:

<C>
  <I>
    <TEXTFORMAT>
      <P>
        <FONT>Here the text I want</FONT>
      </P>
    </TEXTFORMAT>
  </I>
</C>

Everything I've tried so far returns nothing, so I must not correctly reference the contents of the FONT tag.

Which XML path should I use?

+3
source share
2 answers

This will give you an array of node contents FONT.

var array = $(xml).find('FONT').map(function() {
    return $(this).text();
}).get();

Relevant jQuery docs:

+2
function parseXml(xml)
{
    //find every FONT element and store its value
    $(xml).find("FONT").each(function()
    {
        // put this.text() into the array
    });

}
0

Source: https://habr.com/ru/post/1748836/


All Articles