Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing XML with CDATA seems to be not working. #2

Open
ghost opened this issue Jan 24, 2017 · 0 comments
Open

Parsing XML with CDATA seems to be not working. #2

ghost opened this issue Jan 24, 2017 · 0 comments

Comments

@ghost
Copy link

ghost commented Jan 24, 2017

I've tried to parse following xml:

<?xml version="1.0" encoding="utf-8" ?>

<body type="object">
  <clientName>Some Name</clientName>
  <customFields type="object">
    <fax>19271982739127 <![CDATA[ adasdfasdfasd]]></fax>
    <sales type="number">123333</sales>
  </customFields>
  <tags type="array">
    <element>Helicopters</element>
    <element>Transportation</element>
    <element>Railways</element>
  </tags>
  <services type="array">
    <element type="object">
      <serviceName>Mechanics</serviceName>
      <serviceId type="number">111</serviceId>
    </element>
    <element type="object">
      <serviceName>IP</serviceName>
      <serviceId type="number">222</serviceId>
    </element>
  </services>
</body>

When I tried to do this on pegjs.org site using grammar you've provided I have this output (notice <div id="content">):

[
   {
      "body": [
         {
            "@type": "object"
         },
         {
            "clientName": [
               {
                  "#text": "Some Name"
               }
            ]
         },
         {
            "customFields": [
               {
                  "@type": "object"
               },
               {
                  "fax": [
                     {
                        "#text": "19271982739127"
                     },
                     {
                        "#cdata": <div id="content"></div>
                     }
                  ]
               },
               {
                  "sales": [
                     {
                        "@type": "number"
                     },
                     {
                        "#text": "123333"
                     }
                  ]
               }
            ]
         },
         {
            "tags": [
               {
                  "@type": "array"
               },
               {
                  "element": [
                     {
                        "#text": "Helicopters"
                     }
                  ]
               },
               {
                  "element": [
                     {
                        "#text": "Transportation"
                     }
                  ]
               },
               {
                  "element": [
                     {
                        "#text": "Railways"
                     }
                  ]
               }
            ]
         },
         {
            "services": [
               {
                  "@type": "array"
               },
               {
                  "element": [
                     {
                        "@type": "object"
                     },
                     {
                        "serviceName": [
                           {
                              "#text": "Mechanics"
                           }
                        ]
                     },
                     {
                        "serviceId": [
                           {
                              "@type": "number"
                           },
                           {
                              "#text": "111"
                           }
                        ]
                     }
                  ]
               },
               {
                  "element": [
                     {
                        "@type": "object"
                     },
                     {
                        "serviceName": [
                           {
                              "#text": "IP"
                           }
                        ]
                     },
                     {
                        "serviceId": [
                           {
                              "@type": "number"
                           },
                           {
                              "#text": "222"
                           }
                        ]
                     }
                  ]
               }
            ]
         }
      ]
   }
]

Trying to parse this document in node.js produces following error:

message:"content is not defined"
stack:"ReferenceError: content is not defined
   at module.exports.peg$c121 (\projectRoot\Source\Api\node_modules\xmlchecker\lib\xml2jsonModule.js:197:31)
   at peg$parseCdata (\projectRoot\Source\Api\node_modules\xmlchecker\lib\xml2jsonModule.js:1856:16)
   at peg$parseElementContent (\projectRoot\Source\Api\node_modules\xmlchecker\lib\xml2jsonModule.js:1364:12)
   at peg$parseElement (\projectRoot\Source\Api\node_modules\xmlchecker\lib\xml2jsonModule.js:1273:18)
   at peg$parseElementContent (\projectRoot\Source\Api\node_modules\xmlchecker\lib\xml2jsonModule.js:1368:16)
   at peg$parseElement (\projectRoot\Source\Api\node_modules\xmlchecker\lib\xml2jsonModule.js:1273:18)
   at peg$parseElementContent (\projectRoot\Source\Api\node_modules\xmlchecker\lib\xml2jsonModule.js:1368:16)
   at peg$parseElement (\projectRoot\Source\Api\node_modules\xmlchecker\lib\xml2jsonModule.js:1291:20)
   at peg$parseStart (\projectRoot\Source\Api\node_mod...

Hope that helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants