Package Exports
- @titanium/xml2json
- @titanium/xml2json/xml2json.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@titanium/xml2json) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Axway Amplify End-of-Life Announcement
ð See API FAQ below ð
ðŠĶ RIP Axway Amplify Titanium (2010 - 2022)
ðŠĶ RIP Axway Amplify Cloud Services (2012 - 2022)
ð All products affected by the announcements will not be supported by Axway effective their EOL dates in 2022.
Some Open-Source versions of Axway products will live on after End-of-Life (EOL) Axway Amplify product announcements. However, some products are closed-source and will NOT continue after the shut down in 2022.
ð Stay tuned for more info as plans are being made to save the Titanium project and move it under the control of a independent group of developers.
API FAQ:
- API Best Practices
- What is API Security?
- Top API Trends for 2022
- What is a Frankenstein API?
- What is a Zombie API?
- API Developer Experience
- API Cybersecurity 101
- YouTube API Videos
- YouTube API Shorts Videos
@titanium/xml2json
Configurable, lightweight XML to JSON converter for Titanium native mobile apps. Based on https://github.com/metatribal/xmlToJSON by metatribal
- ð Description
- ð Getting Started
- Usage
- ð Related Links
- ð Learn More
- ðĢ Feedback
- ÂĐïļ Legal
ð Description
Features
- no external dependencies
- small (~3kb minified)
- simple parsing. pass either a string or xml node and get back a javascript object ( use JSON.stringify(obj) to get the string representation )
- supports attributes, text, cdata, namespaces, default namespaces, attributes with namespaces... you get the idea
- lots of rendering of options
- consistent, predictable output
- browser support - it works on IE 9+, and nearly every version of Chrome, Safari, and Firefox as well as iOS, Android, and Blackberry. (xmlToJSON will work for IE 7/8 as well if you set the xmlns option to false)
ð Getting Started
Install using npm:
npm install @titanium/xml2json
Usage
const xml2json = require('@titanium/xml2json');
const testString = '<xml><a>It Works!</a></xml>'; // get some xml (string or document/node)
const result = xml2json.parseString(testString); // parse
The (prettified) result of the above code is
{
"xml": {
"a": [
{
"text": "It Works!"
}
]
}
}
Options
// These are the option defaults
var options = {
mergeCDATA: true, // extract cdata and merge with text nodes
grokAttr: true, // convert truthy attributes to boolean, etc
grokText: true, // convert truthy text/attr to boolean, etc
normalize: true, // collapse multiple spaces to single space
xmlns: true, // include namespaces as attributes in output
namespaceKey: '_ns', // tag name for namespace objects
textKey: '_text', // tag name for text nodes
valueKey: '_value', // tag name for attribute values
attrKey: '_attr', // tag for attr groups
cdataKey: '_cdata', // tag for cdata nodes (ignored if mergeCDATA is true)
attrsAsObject: true, // if false, key is used as prefix to name, set prefix to '' to merge children and attrs.
stripAttrPrefix: true, // remove namespace prefixes from attributes
stripElemPrefix: true, // for elements of same name in diff namespaces, you can enable namespaces and access the nskey property
childrenAsArray: true // force children into arrays
};
// you can change the defaults by passing the parser an options object of your own
var myOptions = {
mergeCDATA: false,
xmlns: false,
attrsAsObject: false
}
result = xml2json.parseString(xmlString, myOptions);
A more complicated example (with xmlns: true)
<?xml version="1.0" encoding="UTF-8"?>
<xml xmlns="http://default.namespace.uri">
<a>
<b id="1">one</b>
<b id="2"><![CDATA[some <cdata>]]>two</b>
<ns:c xmlns:ns="http://another.namespace" ns:id="3">three</ns:c>
</a>
</xml>
results in
{
"xml": [{
"attr": {
"xmlns": {
"value": "http://default.namespace.uri"
}
},
"a": [{
"b": [{
"attr": {
"id": {
"value": 1
}
},
"text": "one"
}, {
"attr": {
"id": {
"value": 2
}
},
"text": "some <cdata>two"
}],
"c": [{
"attr": {
"xmlns:ns": {
"value": "http://another.namespace"
},
"id": {
"value": 3
}
},
"text": "three"
}]
}]
}]
}
ð Related Links
- Titanium Mobile - Open-source tool for building powerful, cross-platform native apps with JavaScript.
- Alloy - MVC framework built on top of Titanium Mobile.
- Appcelerator - Installer for the Appcelerator Platform tool
ð Learn More
ðĢ Feedback
Have an idea or a comment? Join in the conversation here!
ÂĐïļ Legal
Alloy is developed by Appcelerator and the community and is Copyright ÂĐ 2012-Present by Appcelerator, Inc. All Rights Reserved.
Alloy is made available under the Apache Public License, version 2. See their license file for more information.
Appcelerator is a registered trademark of Appcelerator, Inc. Titanium is a registered trademark of Appcelerator, Inc. Please see the LEGAL information about using trademarks, privacy policy, terms of usage and other legal information at http://www.appcelerator.com/legal.