XML 2 JSON doesn't work

Not applicable

Taerget retirns XML of teh following format:

<?xml version="1.0"?> <ArrayOfFeature xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Feature> <Descriptor> <Acro>PILPNT</Acro> <Name>Pile</Name> </Descriptor> <DefaultAttributeValue>Ar-Men</DefaultAttributeValue> <ObjectId>00000015006400003137313636323330</ObjectId> </Feature> </ArrayOfFeature>

This is being processed by XML2JSON policy (no conditions) however result of condition is exactly the same XML ...

The only guess I have is that may be because of multiple root tags (there are 2 of them - one <xml> and one <ArrayOfFeature>.

Can someone help please and advise where to look for solution?

Solved Solved
0 6 322
1 ACCEPTED SOLUTION

Hi @Alexey Pirozhnikov

The Content-Type must be "application/xml". Please check the doc here

The HTTP Content-type header of the source message must be set to application/xml, otherwise the policy is not enforced.

View solution in original post

6 REPLIES 6

Not applicable
<?xml version="1.0"?>
<ArrayOfFeature xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Feature>
    <Descriptor>
      <Acro>PILPNT</Acro>
      <Name>Pile</Name>
    </Descriptor>
    <DefaultAttributeValue>Ar-Men</DefaultAttributeValue>
    <ObjectId>00000015006400003137313636323330</ObjectId>
  </Feature>
</ArrayOfFeature>

@Alexey Pirozhnikov Can you share how your XML2JSON policy looks like?

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XMLToJSON async="false" continueOnError="false" enabled="true" name="XJ-FeatureInfo2Json">
    <DisplayName>XJ-FeatureInfo2Json</DisplayName>
    <Properties/>
    <Options/>
    <OutputVariable>response</OutputVariable>
    <Source>response</Source>
</XMLToJSON>

btw removing <xml> didn't help... but I have another idea - this xml is result of nodejs work and it doesn't populate content-type (the reason that it handles multiple flows and they may result in different content-type, in particular xml, json and image).

Is it important to have content-type set to application/xml for the policy to work?

just in case here is complete sample xml:

<?xml version="1.0" encoding="utf-8"?> <ArrayOfFeature xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Feature> <Descriptor> <Acro>PILPNT</Acro> <Name>Pile</Name> </Descriptor> <DefaultAttributeValue>Ar-Men</DefaultAttributeValue> <ObjectId>00000015006400003137313636323330</ObjectId> <Attributes> <AttributeDescriptor> <Name>Object name</Name> <Acro>OBJNAM</Acro> <Value>Ar-Men</Value> </AttributeDescriptor> <AttributeDescriptor> <Name>Scale minimum</Name> <Acro>SCAMIN</Acro> <Value>19999999</Value> </AttributeDescriptor> </Attributes> <Children> <Feature> <Descriptor> <Acro>LIGHTS</Acro> <Name>Light</Name> </Descriptor> <ObjectId>00000048006400003137313636323330</ObjectId> <Attributes> <AttributeDescriptor> <Name>Colour</Name> <Acro>COLOUR</Acro> <Value /> </AttributeDescriptor> <AttributeDescriptor> <Name>Light characteristic</Name> <Acro>LITCHR</Acro> <Value /> </AttributeDescriptor> <AttributeDescriptor> <Name>Scale minimum</Name> <Acro>SCAMIN</Acro> <Value>19999999</Value> </AttributeDescriptor> <AttributeDescriptor> <Name>Signal group</Name> <Acro>SIGGRP</Acro> <Value /> </AttributeDescriptor> <AttributeDescriptor> <Name>Signal period</Name> <Acro>SIGPER</Acro> <Value /> </AttributeDescriptor> </Attributes> <Children /> <Cover> <double>-4.996000025421381</double> <double>48.051000013947487</double> <double>-4.996000025421381</double> <double>48.051000013947487</double> </Cover> <HasMetrics>true</HasMetrics> </Feature> </Children> <Cover> <double>-4.996000025421381</double> <double>48.051000013947487</double> <double>-4.996000025421381</double> <double>48.051000013947487</double> </Cover> <HasMetrics>true</HasMetrics> </Feature> <Feature> <Descriptor> <Acro>PILPNT</Acro> <Name>Pile</Name> </Descriptor> <DefaultAttributeValue>Ar-Men2</DefaultAttributeValue> <ObjectId>00000015006400003137313636323330</ObjectId> <Attributes> <AttributeDescriptor> <Name>Object name</Name> <Acro>OBJNAM</Acro> <Value>Ar-Men</Value> </AttributeDescriptor> <AttributeDescriptor> <Name>Scale minimum</Name> <Acro>SCAMIN</Acro> <Value>19999999</Value> </AttributeDescriptor> </Attributes> <Children> <Feature> <Descriptor> <Acro>LIGHTS</Acro> <Name>Light</Name> </Descriptor> <ObjectId>00000048006400003137313636323330</ObjectId> <Attributes> <AttributeDescriptor> <Name>Colour</Name> <Acro>COLOUR</Acro> <Value /> </AttributeDescriptor> <AttributeDescriptor> <Name>Light characteristic</Name> <Acro>LITCHR</Acro> <Value /> </AttributeDescriptor> <AttributeDescriptor> <Name>Scale minimum</Name> <Acro>SCAMIN</Acro> <Value>19999999</Value> </AttributeDescriptor> <AttributeDescriptor> <Name>Signal group</Name> <Acro>SIGGRP</Acro> <Value /> </AttributeDescriptor> <AttributeDescriptor> <Name>Signal period</Name> <Acro>SIGPER</Acro> <Value /> </AttributeDescriptor> </Attributes> <Children /> <Cover> <double>-4.996000025421381</double> <double>48.051000013947487</double> <double>-4.996000025421381</double> <double>48.051000013947487</double> </Cover> <HasMetrics>true</HasMetrics> </Feature> </Children> <Cover> <double>-4.996000025421381</double> <double>48.051000013947487</double> <double>-4.996000025421381</double> <double>48.051000013947487</double> </Cover> <HasMetrics>true</HasMetrics> </Feature> </ArrayOfFeature>

Hi @Alexey Pirozhnikov

The Content-Type must be "application/xml". Please check the doc here

The HTTP Content-type header of the source message must be set to application/xml, otherwise the policy is not enforced.

yes, it works when content-type is properly set, thanks.