%common;]>...">

Object resolution when parsing xml file in nodejs

My XML file has

<!DOCTYPE application [<!ENTITY % common  SYSTEM "../common.ent">
%common;]>

      

and I used &commonFaults;

, (which is one of the entities defined in the file ./common.ent

) many of which are in the XML file

in my node app I want to inject the string content of the xml file. and in return I want all objects to be resolved.

entrance

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

    <!DOCTYPE application [<!ENTITY % common  SYSTEM "../common.ent">
    %common;]>
    <application xmlns="http://wadl.dev.java.net/2009/02">
        <grammars>
            <include href="../xsd/api.xsd"/>
            <include href="../xsd/api-common.xsd"/>
        </grammars>
        <method name="GET" id="listVersionsv2">
             &commonFaults;
        </method>
    </application>

      

common.ent file:

 <!ENTITY commonFaults
           '
        <response status="503" xmlns="http://wadl.dev.java.net/2009/02">
            <representation mediaType="application/xml" element="csapi:serviceUnavailable"/>
            <representation mediaType="application/json"/>
        </response>
        <response status="400" xmlns="http://wadl.dev.java.net/2009/02">
            <representation mediaType="application/xml" element="csapi:badRequest"/>
            <representation mediaType="application/json"/>
        </response>
           '>

      

Desired output

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

    <!DOCTYPE application [<!ENTITY % common  SYSTEM "../common.ent">
    %common;]>
    <application xmlns="http://wadl.dev.java.net/2009/02">
        <grammars>
            <include href="../xsd/api.xsd"/>
            <include href="../xsd/api-common.xsd"/>
        </grammars>
        <method name="GET" id="listVersionsv2">
        <response status="503" xmlns="http://wadl.dev.java.net/2009/02">
            <representation mediaType="application/xml" element="csapi:serviceUnavailable"/>
            <representation mediaType="application/json"/>
        </response>
        <response status="400" xmlns="http://wadl.dev.java.net/2009/02">
            <representation mediaType="application/xml" element="csapi:badRequest"/>
            <representation mediaType="application/json"/>
        </response>
        </method>
    </application>

      

I am looking xmllint

with an option --noent

that does this efficiently.

I am looking for a similar lib / tool that does this as an npm module that I can "require" in a node application and does the same task as xmllint

.

I dont want to use ChildProcess node.

+3
node.js xml


source to share


No one has answered this question yet

See similar questions:

0
How to use regex to find all xml objects in a multiline string

or similar:

2024
How do you parse and process HTML / XML in PHP?
863
How do I process XML in Python?
492
How to parse XML files?
446
How can I avoid ampersands in XML so that they appear as objects in HTML?
430
How to fix the error: Listen to EADDRINUSE when using nodejs?
375
Web colors in resource xml file for android
292
How to read and parse XML file in C #?
2
Extract HTML from XML file using simpleXML
1
Java and XML: how to get list of included files
0
How can I parse XML document into Python object?



All Articles
Loading...
X
Show
Funny
Dev
Pics