1

I am trying to fetch the xml attribute value using liquid template. Examples are as below.

XML example:

    <ns0:root xmlns:ns0="http://customnamespace.com" xmlns:ns1="http://customnamespace2.com">
  <ns1:product>
  <ns1:name QualifierID="std.lang.all" >TV</ns1:name>
  <ns1:price>499.9</ns1:price>
 </ns1:product>
 </ns0:root>

Liquid Template used:

{
"name": "{{content.product.name['QualifierID']}}",
"price": "{{content.product.price}}",
}

Output expecting :

  {
"name": "std.lang.all",
"price": "499.9"

}

I tried couple of ways but not able to fetch the xml attribute value. it gives me empty value for name.

Best Regards,

Suraj

1 Answers1

2

According to some test, it seems we can't get the attribute(QualifierID) value of the xml by liquid. And I also can not find any useful information about getting attribute value of xml by liquid. But I can provide a workaround for your reference, please refer to my logic below.

1. I initialize a variable named xmlString and set the value with your xml data to simulate your situation. enter image description here

2. I initialize another variable named jsonString and set its value with converting the xmlString to json. enter image description here

3. After that, use "Parse JSON" action to parse the jsonString we get above. And then use "Compose" action to compose the json data which you expected.(The schema in "Parse JSON" was generated by the result from "Initialize variable 2"). enter image description here

Hope it helps~

Hury Shen
  • 14,948
  • 1
  • 9
  • 18
  • Hi @Hury : yep it works with the JSON parsing, but i was trying to see if we can directly fetch it from the xml and doesn't look like we can do that at the moment. Thanks – Suraj Revankar Jun 11 '20 at 09:26
  • XML received is ISO 8859-1 encoded and after doing this, it is leaving extra characters in field for "°C" like this "°C" – Mayank Gupta May 17 '21 at 12:55