0

I have XML:

let rowTest = <?xml version="1.0" encoding="UTF-8"?>
<queryResponse Name="Checked In Guests">
   <rows>
      <row>
         <fields>
            <field name="PartyName" />
            <Notes>Rosen bestellen.</Notes>
            <field name="AccompanyingGuest" name1="Test" name2="" name3="test" BedGuestNum="82259">1418</field>
         </fields>
      </row>
   </rows>
</queryResponse>

I want to get the text in the Notes Tag. But somehow I am able to do that. My try:

 row = parser.parseFromString(rowTest, "text/xml");
 let notes = row.getElementsByTagName("Notes");
 let noteText = notes.textContent;
 console.log(noteText);

undefined

1 Answer 1

1

Try this code.

let rowTest = '<?xml version="1.0" encoding="UTF-8"?> <queryResponse Name="Checked In Guests"> <rows> <row> <fields> <field name="PartyName" /> <Notes>Rosen bestellen.</Notes> <field name="AccompanyingGuest" name1="Test" name2="" name3="test" BedGuestNum="82259">1418</field> </fields> </row> </rows> </queryResponse></xml>';
 parser = new DOMParser();
 row = parser.parseFromString(rowTest, "text/xml");
 let notes = row.getElementsByTagName("Notes")[0];
 let noteText = notes.textContent;
 console.log(noteText);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.