0

I am working on nodejs-expressjs and I got responce as raw XML. which I want to convert into javascript array or json array so that I can retrive the domain name and its status .That name and status I want to show on HTML file. Fowling is my Raw XML

<?xml version='1.0' encoding="UTF-8" standalone="no" ?>
<!DOCTYPE OPS_envelope SYSTEM "ops.dtd">
<OPS_envelope>
 <header>
  <version>0.9</version>
  </header>
 <body>
  <data_block>
   <dt_assoc>
    <item key="response_code">200</item>
    <item key="response_text">Command completed successfully</item>
    <item key="attributes">
     <dt_assoc>
      <item key="lookup">
       <dt_assoc>
        <item key="items">
         <dt_array>
          <item key="0">
           <dt_assoc>
            <item key="status">taken</item>
            <item key="domain">ashok.com</item>
           </dt_assoc>
          </item>
          <item key="1">
           <dt_assoc>
            <item key="domain">ashok.net</item>
            <item key="status">available</item>
           </dt_assoc>
          </item>
          <item key="2">
           <dt_assoc>
            <item key="domain">ashok.org</item>
            <item key="status">available</item>
           </dt_assoc>
          </item>
          <item key="3">
           <dt_assoc>
            <item key="domain">ashok.biz</item>
            <item key="status">available</item>
           </dt_assoc>
          </item>
          <item key="4">
           <dt_assoc>
            <item key="status">available</item>
            <item key="domain">ashok.me</item>
           </dt_assoc>
          </item>
          <item key="5">
           <dt_assoc>
            <item key="domain">ashok.website</item>
            <item key="status">available</item>
            <item key="has_claim">0</item>
           </dt_assoc>
          </item>
         </dt_array>
        </item>
        <item key="response_text">Command completed successfully.</item>
        <item key="response_code">200</item>
        <item key="is_success">1</item>
        <item key="count">6</item>
       </dt_assoc>
      </item>
      <item key="personal_names">
       <dt_assoc>
        <item key="response_code"></item>
       </dt_assoc>
      </item>
     </dt_assoc>
    </item>
    <item key="request_response_time">8.066</item>
    <item key="protocol">XCP</item>
    <item key="is_search_completed">1</item>
    <item key="is_success">1</item>
    <item key="action">REPLY</item>
   </dt_assoc>
  </data_block>
 </body>
</OPS_envelope>

I have convert it into

jsonXml = JSON.stringify(result.OPS_envelope.body.data_block.dt_assoc.item); console.dir(jsonXml);

'["Command completed successfully",{"dt_assoc":{"item":[{"dt_assoc":{"item":[{"dt_array":{"item":[{"dt_assoc":{"item":["anjali.com","taken"]}},{"dt_assoc":{"item":["available","anjali.net"]}},{"dt_assoc":{"item":["anjali.org","available"]}},{"dt_assoc":{"item":["available","anjali.biz"]}},{"dt_assoc":{"item":["available","anjali.me"]}},{"dt_assoc":{"item":["anjali.website","available","0"]}}]}},"Command completed successfully.","200","1","6"]}},{"dt_assoc":{"item":""}}]}},"200","REPLY","1","1","XCP","8.067"]'

and when I use

var json = JSON.parse(jsonXml);

console.log(json);

[ 'Command completed successfully',
  { dt_assoc: { item: [Object] } },
  '200',
  'REPLY',
  '1',
  '1',
  'XCP',
  '8.067' ]

I want to retrieve the domain name and they are taken/available from json output as javascript array but I am unable to do that.

Or may you know any other method to retrieve domain_name and status .

Please help me for same.

web
  • 25
  • 4

1 Answers1

0

There is a ton of different ways of doing this.

You can use the DOMParser you can find out about this at w3schools and mdn.

You can use a library like JQuery or xml2json or any of the many npm packages on the matter.

Do it yourself, here is a blog about it.

Michael Warner
  • 3,879
  • 3
  • 21
  • 45