Php xml_parser_create() function

Comments and Discussions

You must Sign In to use this message board.
First Prev
spyhunter88 31-Jul-11 15:36 
BratilaRazvan 31-Jul-11 22:09 
cccfff777 26-Apr-11 5:02 
maplewang 21-Oct-10 14:57 
Aescleal 4-Oct-10 11:05 
Galatei 3-Oct-10 0:58 
Lorenzo Gatti 3-Oct-10 21:36 
BratilaRazvan 4-Oct-10 23:46 
Aescleal 5-Oct-10 1:19 
BratilaRazvan 5-Oct-10 1:38 
Aescleal 5-Oct-10 3:24 
Lorenzo Gatti 27-Sep-10 21:11 
BratilaRazvan 28-Sep-10 2:21 
BratilaRazvan 28-Sep-10 4:12 
BratilaRazvan 28-Sep-10 23:22 
BratilaRazvan 1-Oct-10 3:29 
Lorenzo Gatti 3-Oct-10 21:55 
FrankLaPiana 27-Sep-10 15:51 
xComaWhitex 24-Sep-10 20:50 
BratilaRazvan 24-Sep-10 22:24 
xComaWhitex 24-Sep-10 22:38 
BratilaRazvan 24-Sep-10 23:18 
xComaWhitex 24-Sep-10 23:26 
BratilaRazvan 24-Sep-10 23:36 
xComaWhitex 24-Sep-10 23:38 

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin   


Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

What is the DOM?

The DOM defines a standard for accessing and manipulating documents:

«The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document.»

The HTML DOM defines a standard way for accessing and manipulating HTML documents. It presents an HTML document as a tree-structure.

The XML DOM defines a standard way for accessing and manipulating XML documents. It presents an XML document as a tree-structure.

Understanding the DOM is a must for anyone working with HTML or XML.

Simple as pie usage

That’s right, if you have been using xml-simple or a home-grown wrapper, this was added in 0.1.11 just for you:

var fs =require('fs'),    xml2js =require('xml2js');var parser =newxml2js.Parser();fs.readFile(__dirname+'/foo.xml',function(err,data){parser.parseString(data,function(err,result){console.dir(result);console.log('Done');});});

Look ma, no event listeners!

fs =require'fs',xml2js =require'xml2js'parser =newxml2js.Parser()fs.readFile __dirname+'/foo.xml', (err, data)->  parser.parseString data, (err, result)->console.dir resultconsole.log'Done.'

But what happens if you forget the keyword to create a new ? In the middle of a nightly coding session, it might get lost, after all. Worry not, we got you covered! Starting with 0.2.8 you can also leave it out, in which case will helpfully add it for you, no bad surprises and inexplicable bugs!

Examples

The following example illustrates the basic usage of js2xmlparser:

var js2xmlparser =require("js2xmlparser");var obj ={"firstName""John","lastName""Smith","dateOfBirth"newDate(1964,7,26),"address"{"@"{"type""home"},"streetAddress""3212 22nd St","city""Chicago","state""Illinois","zip"10000},"phone"{"@"{"type""home"},"#""123-555-4567"},{"@"{"type""cell"},"#""890-555-1234"},{"@"{"type""work"},"#""567-555-8901"},"email""john@smith.com"};console.log(js2xmlparser.parse("person", obj));

This example produces the following XML:

<?xml version='1.0'?><person><firstName>John</firstName><lastName>Smith</lastName><dateOfBirth>Wed Aug 26 1964 00:00:00 GMT-0400 (Eastern Summer Time)</dateOfBirth><addresstype='home'><streetAddress>3212 22nd St</streetAddress><city>Chicago</city><state>Illinois</state><zip>10000</zip></address><phonetype='home'>123-555-4567</phone><phonetype='cell'>890-555-1234</phone><phonetype='work'>567-555-8901</phone><email>john@smith.com</email></person>

Additional examples can be found in the examples directory.

Display the First CD in an HTML div Element

This example uses a function to display the first CD element in an HTML element with id=»showCD»:

Example

displayCD(0);function displayCD(i) {  var xmlhttp = new XMLHttpRequest();  xmlhttp.onreadystatechange = function() {    if (this.readyState == 4 && this.status == 200) {      myFunction(this, i);     }  };  xmlhttp.open(«GET», «cd_catalog.xml», true);  xmlhttp.send();}function myFunction(xml, i) {  var xmlDoc = xml.responseXML;   x = xmlDoc.getElementsByTagName(«CD»);  document.getElementById(«showCD»).innerHTML =  «Artist: » +  x.getElementsByTagName(«ARTIST»).childNodes.nodeValue +  «<br>Title: » +  x.getElementsByTagName(«TITLE»).childNodes.nodeValue +  «<br>Year: » +   x.getElementsByTagName(«YEAR»).childNodes.nodeValue; }

Display the First CD in an HTML div Element

This example uses a function to display the first CD element in an HTML element with id=»showCD»:

Example

displayCD(0);function displayCD(i) {    var xmlhttp = new XMLHttpRequest();    xmlhttp.onreadystatechange = function() {        if (this.readyState == 4 && this.status == 200) {            myFunction(this, i);        }    };    xmlhttp.open(«GET», «cd_catalog.xml», true);    xmlhttp.send();}function myFunction(xml, i) {    var xmlDoc = xml.responseXML;     x = xmlDoc.getElementsByTagName(«CD»);    document.getElementById(«showCD»).innerHTML =    «Artist: » +    x.getElementsByTagName(«ARTIST»).childNodes.nodeValue +    «<br>Title: » +    x.getElementsByTagName(«TITLE»).childNodes.nodeValue +    «<br>Year: » +     x.getElementsByTagName(«YEAR»).childNodes.nodeValue; }

Options for Custom Processing Functions

For XML → JS object / JSON, following custom callback functions can be supplied:

var convert =require('xml-js');var xml ='<foo:Name>Ali</Name> <bar:Age>30</bar:Age>';var options ={compacttrue,elementNameFnfunction(val){returnval.replace('foo:','').toUpperCase();}};var result =convert.xml2json(xml, options);console.log(result);
Option Signature Description
To perform additional processing for DOCTYPE. For example,
To perform additional processing for content of Processing Instruction value. For example, . Note: will be an object if is enabled.
To perform additional processing for CData. For example, .
To perform additional processing for comments. For example, .
To perform additional processing for texts inside elements. For example, .
To perform additional processing for Processing Instruction name. For example, . Note: will be an object if is enabled.
To perform additional processing for element name. For example, .
To perform additional processing for attribute name. For example, .
To perform additional processing for attributeValue. For example, .
To perform additional processing for attributes object. For example, .

For JS object / JSON → XML, following custom callback functions can be supplied:

var convert =require('xml-js');var json ='{"name":{"_text":"Ali"},"age":{"_text":"30"}}';var options ={compacttrue,textFnfunction(val,elementName){return elementName ==='age'? val +'';}};var result =convert.json2xml(json, options);console.log(result);
Option Signature Description
To perform additional processing for DOCTYPE. For example, .
To perform additional processing for content of Processing Instruction value. For example, . Note: will be an object if is enabled.
To perform additional processing for CData. For example, .
To perform additional processing for comments. For example, .
To perform additional processing for texts inside elements. For example, .
To perform additional processing for Processing Instruction name. For example, . Note: will be an object if is enabled.
To perform additional processing for element name. For example, .
To perform additional processing for attribute name. For example, .
To perform additional processing for attributeValue. For example, .
To perform additional processing for attributes object. For example, .
Whether to generate full tag or just self closing tag for elements that has no sub elements. For example, .

Because any good library should support command line usage, this library is no different.

DOM

The method of xml-parser instance returns a Document-Object-Model with a few methods. It is oriented on the official W3 DOM but not complex as the original.

constxml=require("xml-parse");var xmlDoc =newxml.DOM(xml.parse('<?xml version="1.0" encoding="UTF-8"?>'+'<root>Root Element</root>'));xmlDoc.document;
var objectNode =document.childNodes1;objectNode ={  type'element',  tagName'tagName',  attributesObject,  childNodesObject,  innerXML'innerXML',  closingtrue,  closingCharnull,  getElementsByTagNameFunction,  getElementsByAttributeFunction,  removeChildFunction,  appendChildFunction,  insertBeforeFunction,  getElementsByCheckFunctionFunction,  parentNodeCircular}

With or methods of every object node, you are allowed to append a child node. You do not have to do something like .

Because a child node is just an object literal, with some properties like , , and more you just have to pass such an object to the function.

element.appendChild(childNode);
constxml=require('xml-parse');var xmlDoc =newxml.DOM(xml.parse('<?xml version="1.0" encoding="UTF-8"?>'+'<root>Root Element</root>'));var root =xmlDoc.document.getElementsByTagName("root");root.appendChild({  type"element",  tagName"appendedElement",  childNodes{      type"text",      text"Hello World :) I'm appended!"}});
element.insertBefore(childNode, elementAfter);
constxml=require('xml-parse');var xmlDoc =newxml.DOM(xml.parse('<?xml version="1.0" encoding="UTF-8"?>'+'<root>Root Element</root>'));var root =xmlDoc.document.getElementsByTagName("root");root.insertBefore({  type"element",  tagName"insertedElement",  childNodes{      type"text",      text"Hello World :) I'm appended!"}},root.childNodes);
element.removeChild(childNode);
constxml=require('xml-parse');var xmlDoc =newxml.DOM(xml.parse('<?xml version="1.0" encoding="UTF-8"?>'+'<root>Root Element</root>'));var root =xmlDoc.document.getElementsByTagName("root");root.removeChild(root.childNodes);

The of a object node represents its parent element. It’s a reference.

constxml=require('xml-parse');var xmlDoc =newxml.DOM(xml.parse('<?xml version="1.0" encoding="UTF-8"?>'+'<root>Root Element</root>'));var root =xmlDoc.document.getElementsByTagName("root");console.log(root.childNodes.parentNode);

Benchmark

report

file size fxp 3.0 validator (rps) fxp 3.0 parser (rps) xml2js 0.4.19 (rps)
1.5k 16581.06758 14032.09323 4615.930805
1.5m 14918.47793 13.23366098 5.90682005
13m 1.834479235 1.135582008 -1
1.3k with CDATA 30583.35319 43160.52342 8398.556349
1.3m with CDATA 27.29266471 52.68877009 7.966000795
1.6k with cdata,prolog,doctype 27690.26082 41433.98547 7872.399268
98m 0.08473858148 0.2600104004 -1

-1 indicates error or incorrect output.

report

file size fxp 3.2 js to xml xml2js 0.4.19 builder
1.3k 160148.9801 10384.99401
1.1m 173.6374831 8.611884025

Currently FXP fails to parse XML with attributes has «>» in the value. This problem is left open as change in regex for its fix is degrading the performance. And the parser become very slow in case of long attribute names. However, it is not ignored and we’re working on the fix.

  • : A standard to represent any number in the universe in comparatively less space and without precision loss. A standard to save memory to represent any text string in comparision of UTF encodings.
  • : Speedup and simplify image labeling / annotation. Supports multiple formats, one click annotation, easy interface and much more. There are more than half million images are being annotated every month using this tool.
  • : The fastest and simple router for node js web frameworks with many unique features.

Options for Changing Key Names

To change default key names in the output object or the default key names assumed in the input JavaScript object / JSON, use the following options:

Option Default Description
or Name of the property key which will be used for the declaration. For example, if then output of will be (in compact form)
or Name of the property key which will be used for the processing instruction. For example, if then output of will be (in compact form)
or Name of the property key which will be used for the attributes. For example, if then output of will be (in compact form)
or Name of the property key which will be used for the text. For example, if then output of will be (in compact form)
or Name of the property key which will be used for the cdata. For example, if then output of will be (in compact form)
or Name of the property key which will be used for the doctype. For example, if then output of will be (in compact form)
or Name of the property key which will be used for the comment. For example, if then output of will be (in compact form)
or Name of the property key which will be used for the parent. For example, if then output of will be (in compact form)
Name of the property key which will be used for the type. For example, if then output of will be (in non-compact form)
Name of the property key which will be used for the name. For example, if then output of will be (in non-compact form)
Name of the property key which will be used for the elements. For example, if then output of will be (in non-compact form)

Two default values mean the first is used for non-compact output and the second is for compact output.

PHP XML Parser Constants

Constant
XML_ERROR_NONE (integer)
XML_ERROR_NO_MEMORY (integer)
XML_ERROR_SYNTAX (integer)
XML_ERROR_NO_ELEMENTS (integer)
XML_ERROR_INVALID_TOKEN (integer)
XML_ERROR_UNCLOSED_TOKEN (integer)
XML_ERROR_PARTIAL_CHAR (integer)
XML_ERROR_TAG_MISMATCH (integer)
XML_ERROR_DUPLICATE_ATTRIBUTE (integer)
XML_ERROR_JUNK_AFTER_DOC_ELEMENT (integer)
XML_ERROR_PARAM_ENTITY_REF (integer)
XML_ERROR_UNDEFINED_ENTITY (integer)
XML_ERROR_RECURSIVE_ENTITY_REF (integer)
XML_ERROR_ASYNC_ENTITY (integer)
XML_ERROR_BAD_CHAR_REF (integer)
XML_ERROR_BINARY_ENTITY_REF (integer)
XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF (integer)
XML_ERROR_MISPLACED_XML_PI (integer)
XML_ERROR_UNKNOWN_ENCODING (integer)
XML_ERROR_INCORRECT_ENCODING (integer)
XML_ERROR_UNCLOSED_CDATA_SECTION (integer)
XML_ERROR_EXTERNAL_ENTITY_HANDLING (integer)
XML_OPTION_CASE_FOLDING (integer)
XML_OPTION_TARGET_ENCODING (integer)
XML_OPTION_SKIP_TAGSTART (integer)
XML_OPTION_SKIP_WHITE (integer)
XML_SAX_IMPL (string)

Options for the Builder class

These options are specified by . Possible options are:

  • (default: ): Prefix that is used to access the attributes. Version 0.1 default was .
  • (default: ): Prefix that is used to access the character content. Version 0.1 default was .
  • (default or the root key name): root element name to be used in case is or to override the root element name.
  • (default ): Rendering options for xmlbuilder-js.
    • pretty: prettify generated XML
    • indent: whitespace for indentation (only when pretty)
    • newline: newline char (only when pretty)
  • (default : XML declaration attributes.
    • A version number string, e.g. 1.0
    • Encoding declaration, e.g. UTF-8
    • standalone document declaration: true or false
  • (default ): optional DTD. Eg.
  • (default: ): omit the XML header. Added in 0.4.3.
  • (default: ): allows using characters from the Unicode surrogate blocks.
  • (default: ): wrap text nodes in instead of escaping when necessary. Does not add if it is not required. Added in 0.4.5.

Version 0.2 changed the default parsing settings, but version 0.1.14 introduced the default settings for version 0.2, so these settings can be tried before the migration.

var xml2js =require('xml2js');var parser =newxml2js.Parser(xml2js.defaults"0.2");

To get the 0.1 defaults in version 0.2 you can just use in the same place. This provides you with enough time to migrate to the saner way of parsing in 0.2. We try to make the migration as simple and gentle as possible, but some breakage cannot be avoided.

So, what exactly did change and why? In 0.2 we changed some defaults to parse the XML in a more universal and sane way. So we disabled and so does not cut out any text content. You can reenable this at will of course. A more important change is that we return the root tag in the resulting JavaScript structure via the setting, so you need to access the first element. This is useful for anybody who wants to know what the root node is and preserves more information. The last major change was to enable , so everytime it is possible that one might embed more than one sub-tag into a tag, xml2js >= 0.2 returns an array even if the array just includes one element. This is useful when dealing with APIs that return variable amounts of subtags.

The development requirements are handled by npm, you just need to install them. We also have a number of unit tests, they can be run using directly from the project root. This runs zap to discover all the tests and execute them.

If you like to contribute, keep in mind that is written in CoffeeScript, so don’t develop on the JavaScript files that are checked into the repository for convenience reasons. Also, please write some unit test to check your behaviour and if it is some user-facing thing, add some documentation to this README, so people will know it exists. Thanks in advance!

Please, if you have a problem with the library, first make sure you read this README. If you read this far, thanks, you’re good. Then, please make sure your problem really is with . It is? Okay, then I’ll look at it. Send me a mail and we can talk. Please don’t open issues, as I don’t think that is the proper forum for support problems. Some problems might as well really be bugs in , if so I’ll let you know to open an issue instead 🙂

But if you know you really found a bug, feel free to open an issue instead.

Just Get The Job Done

So, you don’t care about XML correctness. Performance isn’t an issue for you. Streaming is irrelevant. All you want is something that gets XML into memory and allows you to stick it back onto disk again. What you care about is API.

You want an XML parser that’s going to be small, easy to install, trivial to use, and small enough to be irrelevant to your eventual executable’s size.

You have chosen:


I put TinyXML in this slot because it is about as braindead simple to use as XML parsers get. Yes, it’s slow, but it’s simple and obvious. It has a lot of convenience functions for converting attributes and so forth.

Writing XML is no problem in TinyXML. You just up some objects, attach them together, send the document to a , and everyone’s happy.

There is also something of an ecosystem built around TinyXML, with a more iterator-friendly API, and even an XPath 1.0 implementation layered on top of it.

Parameter Values

Parameter Description
parser Required. Specifies the XML parser to use
option Required. Specifies the option to set. Possible values:
  • XML_OPTION_CASE_FOLDING — Specifies if case-folding is enabled. Can be 1 (TRUE) or 0 (FALSE). 1 is default
  • XML_OPTION_SKIP_TAGSTART — Specifies how many characters should be skipped in the beginning of a tag name
  • XML_OPTION_SKIP_WHITE — Specifies whether to skip values consisting of whitespace characters. Can be 1 (TRUE) or 0 (FALSE)
  • XML_OPTION_TARGET_ENCODING — Specifies the target encoding in this XML parser. Set to the same as the xml_parser_create() function by default (ISO-8859-1, US-ASCII or UTF-8)
value Required. Specifies options new value

What is New

This project has been designed with simplicity in mind, in order to be able to assimilate the code base quickly and easily and add to it the extra functionality needed by each specific application.

These classes provide only the basic functionality, therefore is the most lightweight parser from all that I could find: 500 lines of code for the parser (including some unused functions, which can be removed if necessary), and another 500 for the binary tree construct. If more functionality is needed, this has to be added in order to fulfill one’s needs.

It is very easy to understand and work with this code as a base for further development.

The parsing function is iterative, it only goes once through the XML string, so the performance is quite satisfactory. The memory requirements are low, each object allocates just how much memory it actually needs. There is much more room for improvement, but it is not the target of this project.

The HTML DOM

All HTML elements can be accessed through the HTML DOM.

This example changes the value of an HTML element with id=»demo»:

Example

<h1 id=»demo»>This is a Heading</h1><script> document.getElementById(«demo»).innerHTML = «Hello World!»;</script>

This example changes the value of the first <h1> element in an HTML document:

Example

<h1>This is a Heading</h1><h1>This is a Heading</h1><script> document.getElementsByTagName(«h1»).innerHTML = «Hello World!»; </script>

Note: Even if the HTML document contains only ONE <h1> element you still have to specify the array index , because the getElementsByTagName() method always returns an array.

You can learn a lot more about the HTML DOM in our JavaScript tutorial.

PHP XML Parser Introduction

The XML functions lets you parse, but not validate, XML documents.

XML is a data format for standardized structured document exchange. More information on XML can be found in our XML Tutorial.

This extension uses the Expat XML parser.

Expat is an event-based parser, it views an XML document as a series of events. When an event occurs, it calls a specified function to handle it.

Expat is a non-validating parser, and ignores any DTDs linked to a document. However, if the document is not well formed it will end with an error message.

Because it is an event-based, non validating parser, Expat is fast and well suited for web applications.

The XML parser functions lets you create XML parsers and define handlers for XML events.

Compact vs Non-Compact

Most XML to JSON converters (including online converters) convert to some compact output like instead of non-compact output like .

While compact output might work in most situations, there are cases when elements of different names are mixed inside a parent element. Lets use as an example. Most converters will produce compact output like this , which has merged both elements into an array. If you try to convert this back to xml, you will get which has not preserved the order of elements!

The reason behind this behavior is due to the inherent limitation in the compact representation. Because output like is illegal (same property name should not appear twice in an object). This leaves no option but to use array .

The non-compact output, which is supported by this library, will produce more information and always guarantees the order of the elements as they appeared in the XML file.


Another drawback of compact output is the resultant element can be an object or an array and therefore makes the client code a little awkward in terms of the extra check needed on object type before processing.

NOTE: Although non-compact output is more accurate representation of original XML than compact version, the non-compact version is verbose and consumes more space. This library provides both options. Use if you are not sure because it preserves everything; otherwise use if you want to save space and you don’t care about mixing elements of same name and losing their order.

Initializing the XML Expat Parser

We want to initialize the XML Expat Parser in PHP, define some handlers for different XML events, and then parse the XML file.

Example

<?php // Initialize the XML parser $parser=xml_parser_create(); // Function to use at the start of an element function start($parser,$element_name,$element_attrs) {   switch($element_name) {     case «NOTE»:     echo «— Note —<br>»;     break;     case «TO»:     echo «To: «;     break;     case «FROM»:     echo «From: «;     break;     case «HEADING»:     echo «Heading: «;     break;     case «BODY»:     echo «Message: «;   } } // Function to use at the end of an element function stop($parser,$element_name) {   echo «<br>»; } // Function to use when finding character data function char($parser,$data) {   echo $data; } // Specify element handler xml_set_element_handler($parser,»start»,»stop»); // Specify data handler xml_set_character_data_handler($parser,»char»); // Open XML file $fp=fopen(«note.xml»,»r»); // Read data while ($data=fread($fp,4096)) {   xml_parse($parser,$data,feof($fp)) or   die (sprintf(«XML Error: %s at line %d»,   xml_error_string(xml_get_error_code($parser)),   xml_get_current_line_number($parser))); } // Free the XML parser xml_parser_free($parser); ?>

Example explained:

  1. Initialize the XML parser with the function
  2. Create functions to use with the different event handlers
  3. Add the function to specify which function will be executed when the parser encounters the opening and closing tags
  4. Add the function to specify which function will execute when the parser encounters character data
  5. Parse the file «note.xml» with the function
  6. In case of an error, add function to convert an XML error to a textual description
  7. Call the function to release the memory allocated with the function

Loading an XML File

The XML file used in the examples below is books.xml.

This example reads «books.xml» into xmlDoc and retrieves the text value of the first <title> element in books.xml:

Example

<!DOCTYPE html> <html> <body> <p id=»demo»></p> <script> var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() {     if (this.readyState == 4 && this.status == 200) {     myFunction(this);     } }; xhttp.open(«GET», «books.xml», true); xhttp.send(); function myFunction(xml) {    var xmlDoc = xml.responseXML;     document.getElementById(«demo»).innerHTML =     xmlDoc.getElementsByTagName(«title»).childNodes.nodeValue; } </script> </body> </html>

XML builder usage

Since 0.4.0, objects can be also be used to build XML:

var xml2js =require('xml2js');var obj ={name"Super", Surname"Man", age23};var builder =newxml2js.Builder();var xml =builder.buildObject(obj);

At the moment, a one to one bi-directional conversion is guaranteed only for default configuration, except for , and options you can redefine to your taste. Writing CDATA is supported via setting the option to .

To specify attributes:

var xml2js =require('xml2js');var obj ={root{${id"my id"}, _"my inner text"}};var builder =newxml2js.Builder();var xml =builder.buildObject(obj);

You can generate XML that declares XML namespace prefix / URI pairs with xmlns attributes.

Example declaring a default namespace on the root element:

let obj ={  Foo{    ${"xmlns""http://foo.com"}}};

Result of :

<Fooxmlns="http://foo.com"/>

Example declaring non-default namespaces on non-root elements:

let obj ={'foo:Foo'{    ${'xmlns:foo''http://foo.com'},'bar:Bar'{      ${'xmlns:bar''http://bar.com'}}}}

Result of :

<fooFooxmlnsfoo="http://foo.com"><barBarxmlnsbar="http://bar.com"/></fooFoo>

Features

Since XML is a data-interchange format, js2xmlparser is designed primarily for JSON-type objects, arrays and primitive data types, like many of the other JavaScript to XML parsers currently available for Node.js.

However, js2xmlparser is capable of parsing any object, including native JavaScript objects such as and , by taking advantage of each object’s function or, if this function does not exist, the constructor.

js2xmlparser also has support for the and objects introduced in ECMAScript 2015, treating them as JSON-type objects and arrays respectively. Support for s is necessary to generate XML with elements in a specific order, since JSON-type objects do not guarantee insertion order. keys are always converted to strings using the method described above.

js2xmlparser also supports a number of constructs unique to XML:

  • attributes (through an attribute property in objects)
  • mixed content (through value properties in objects)
  • multiple elements with the same name (through arrays)

js2xmlparser can also pretty-print the XML it outputs.


С этим читают