Search code examples
xmlangularbpmnngx-xml2json

How can I parse through XML code and get required properties and values


I am using angular and I am recieving an xml response from my api call. Out of XML want name attribute of property bpmn:task.

<bpmn:process>
<bpmn:task Id= "Loopin809" name="Process 1"  >
<bpmn:Incoming> Sequence 1</bpmn:Incoming>
<bpmn:Outgoing> Sequence 2</bpmn:Outgoing>
</bpmn:task>
<bpmn:task Id= "Loopin8091" name="Process 2"  >
<bpmn:Incoming> Sequence 3</bpmn:Incoming>
<bpmn:Outgoing> Sequence 4</bpmn:Outgoing>
</bpmn:task>
<bpmn:task Id= "Loopin80973" name="Process 3"  >
<bpmn:Incoming> Sequence 5</bpmn:Incoming>
<bpmn:Outgoing> Sequence 6</bpmn:Outgoing>
</bpmn:task>
</brpmn:process>

I tried converting XML into JSON using NgxXml2Json, however, I am not able get the property "name", I am able to retrieve ID, but the name is what I am not able to retrieve. All I want is vale of name inside bpmn:task property. (Hint name="Process 1" )


Solution

  • Update: I have used ngx-xml2json npm module, and was able to parse throught my xml tree and all the properties and their attributes. yourXml: string;

      const standardParser = new DOMParser();
      const standardXml = standardParser.parseFromString(
        yourxml,
        'text/xml'
      );
      const standardObj = this.ngxXml2jsonService.xmlToJson(standardXml);
    

    this solved my problem, thanks to everyone, who gave it a try.