1

Hi i have parsed the Xml to JSON using xml2js package in node js. The result is like as follows..

enter image description here

Now i need to get the properties of JSON object, like

result.env:Envelope

but it generates compile time error. How can i access the object. Any help ??

Saad Zulfiqar
  • 410
  • 5
  • 16

1 Answers1

2

you can access it by result['env:Envelope'].

Suppose you have xml with namespace as follows:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <GetItems xmlns="http://www.test.com">
         <Items>
            <Object d3p1:type="Fruits" xmlns:d3p1="http://www.w3.org/2001/XMLSchema-instance">
               <Key>11032896</Key>
               <Name>Apple</Name>
            </Object>
            <Object d3p1:type="Fruits" xmlns:d3p1="http://www.w3.org/2001/XMLSchema-instance">
               <Key>11662896</Key>
               <Name>Banana</Name>
            </Object>
        </Items>
    </GetItems>
    </s:Body>
</s:Envelope>

You can access it with out getting compile error in TypeScript as

result['Envelope']['Body']['GetItems']['Items']['Object']
coolcake
  • 2,917
  • 8
  • 42
  • 57
Tuan Anh Tran
  • 6,807
  • 6
  • 37
  • 54
  • 1
    While this may answer the question, it is very very skimpy. You should add a sentence or two explaining how this does what it does, and maybe a link to appropriate documentation. – Ross Presser Oct 26 '17 at 13:56