Reputation: 780
I am using getElementsByTagName
in this context
TheTitle = xmlDoc.getElementsByTagName("ArticleTitle")[i].childNodes[0].nodeValue;
to obtain the node value but when the text includes triangle brackets such as:
<ArticleTitle>"The Cat Sat on The <i>Mat</i>"</ArticleTitle>
I am only able to retrieve
The Cat Sat on The
How can I prevent triangle brackets in the node text from prematurely ending text capture?
Upvotes: 0
Views: 42
Reputation: 6264
<ArticleTitle>"The Cat Sat on The <i>Mat</i>"</ArticleTitle>
has three child nodes
The Cat Sat on The
<i>
node with <i>Mat</i>
"
So, .childNodes[0].nodeValue;
will, of course, be just The Cat Sat on The
To fix, use:
TheTitle = xmlDoc.getElementsByTagName("ArticleTitle")[i].textContent;
instead
let doc = `<xml><ArticleTitle>"The Cat Sat on The <i>Mat</i>"</ArticleTitle></xml>`;
let xmlDoc = new DOMParser().parseFromString(doc, 'text/xml');
let TheTitle = xmlDoc.getElementsByTagName("ArticleTitle")[0].textContent;
console.log(TheTitle);
Upvotes: 1