简体   繁体   中英

How to store an xml data format into a string in javascript?

How can we store an xml data format into a string in javascript. I want to store the xml below. How can we store that xml data below ? Is escaping special characters in a string a solution to that ?

xml

<?xml version="1.0" encoding="UTF-8"?>
  <?ADF VERSION="1.0"?>
    <adf>
      <prospect>
        <id sequence="yourLeadID" source="site name"></id>
        <requestdate>2013-03-15T8:22:40</requestdate>
        <vehicle interest="buy" status="used">
        <vin>4RT6FGE6HJ78F3DF56</vin>
        <year>2013</year>
        <make>Ford</make>
        <model>Ford Focus</model&gt
        <stock>4321</stock>
        </vehicle>

      <customer>
        <contact>
        <name part="first" type="individual">John</name>
        <name part="last" type="individual">XYZ</name>
        <email>john at example.com</email>
        <phone type="home">111-222-7777</phone>
        <phone type="mobile">111-444-5555</phone>
        <phone type="work">111-222-3333</phone>
        </contact>
        <comments>Inquiry regarding vehicle</comments>
      </customer>

      <vendor>
       <contact>
       <name part="full">website name from where you are sending email</name>
       <email>john at example.com</email>
       <phone type="business">111-666-7777</phone>
       </contact>
     </vendor>
 </prospect>
</adf> 

You can put it into a string using template literals like this:

const smlString = `
<?xml version="1.0" encoding="UTF-8"?>
  <?ADF VERSION="1.0"?>
    <adf>
      <prospect>
        <id sequence="yourLeadID" source="site name"></id>
        <requestdate>2013-03-15T8:22:40</requestdate>
        <vehicle interest="buy" status="used">
        <vin>4RT6FGE6HJ78F3DF56</vin>
        <year>2013</year>
        <make>Ford</make>
        <model>Ford Focus</model&gt
        <stock>4321</stock>
        </vehicle>

      <customer>
        <contact>
        <name part="first" type="individual">John</name>
        <name part="last" type="individual">XYZ</name>
        <email>john at example.com</email>
        <phone type="home">111-222-7777</phone>
        <phone type="mobile">111-444-5555</phone>
        <phone type="work">111-222-3333</phone>
        </contact>
        <comments>Inquiry regarding vehicle</comments>
      </customer>

      <vendor>
       <contact>
       <name part="full">website name from where you are sending email</name>
       <email>john at example.com</email>
       <phone type="business">111-666-7777</phone>
       </contact>
     </vendor>
 </prospect>
</adf> 
`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM