Skip to content

Unexpected output for XML with certain type of comments. #423

@VShingala

Description

@VShingala
  • Are you running the latest version?
  • Have you included sample input, output, error, and expected output?
  • Have you checked if you are using correct configuration?
  • Did you try online tool?

Description

For mentioned valid input, parser doesn't parse data correctly. As can be seen in the output, an extra node named <-- is introduced for comment.

I understand that adding space before and after comment (<!-- >> ISO DICTIONARY TYPES << -->) solves the issue but, wanted to know if there is any issue in understanding such comments by parser. Also XML is suggested valid in online tool.

Input

<xsd:element name="AccountHolderDetails">
   <xsd:complexType>
       <xsd:sequence>
            <!-->> ISO DICTIONARY TYPES <<-->
            <xsd:element minOccurs="0" name="address" nillable="true" type="Address" />
       </xsd:sequence>
   </xsd:complexType>
</xsd:element>

Code

const fastXMLParser = require('fast-xml-parser'),
  options = {
    ignoreAttributes: false,
    ignoreNameSpace: false,
    parseNodeValue: true,
    trimValues: true
  };

const parsed = fastXMLParser.parse(xmlDocument, options);

Output

{
  "xsd:element": {
    "@_name": "AccountHolderDetails",
    "xsd:complexType": {
      "xsd:sequence": {
        "#text": "> ISO DICTIONARY TYPES",
        "<--": {
          "xsd:element": {
            "@_minOccurs": "0",
            "@_name": "address",
            "@_nillable": "true",
            "@_type": "Address"
          }
        }
      }
    }
  }
}

expected data

{
  "xsd:element": {
    "@_name": "AccountHolderDetails",
    "xsd:complexType": {
      "xsd:sequence": {
        "xsd:element": {
          "@_minOccurs": "0",
          "@_name": "address",
          "@_nillable": "true",
          "@_type": "Address"
        }
      }
    }
  }
}

Would you like to work on this issue?

  • Yes
  • No

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions