A NativeScript module that provides handling XML data as objects similar to LINQ to XML.
npm i --save nativescript-xmlobjects
  • Version: 1.1.4
  • GitHub:
  • Downloads:
    • Last Day:   0
    • Last Week:  0
    • Last Month: 0

npm npm

NativeScript XML Objects

A NativeScript module that provides handling XML data as objects similar to LINQ to XML.


NativeScript Toolbox

This module is part of nativescript-toolbox.


MIT license


  • Android
  • iOS



tns plugin add nativescript-xmlobjects

inside your app project to install the module.


import XmlObjects = require('nativescript-xmlobjects');

var doc = XmlObjects.parse(`<PurchaseOrder PurchaseOrderNumber="99503" OrderDate="1999-10-20">
<Address Type="Shipping">
<Name>Ellen Adams</Name>
<Street>123 Maple Street</Street>
<City>Mill Valley</City>
<Address Type="Billing">
<Name>Tai Yee</Name>
<Street>8 Oak Avenue</Street>
<City>Old Town</City>
<DeliveryNotes>Please leave packages in shed by driveway.</DeliveryNotes>
<Item PartNumber="872-AA">
<Comment>Confirm this is electric</Comment>
<Item PartNumber="926-AA">
<ProductName>Baby Monitor</ProductName>

Enumerate nodes:

// XElement
var rootElement = doc.root;

// XElement[]
var allChildElements = rootElement.elements();

var addressElements = rootElement.elements('Address');
for (var i = 0; i < addressElements.length; i++) {
var ae = addressElements[i];

// XAttribute
var typeAttribute = ae.attribute('Type');
console.log('Type attribute: ' + typeAttribute.value);

// XNode[]
var allNodes = rootElement.nodes();
for (var i = 0; i < allNodes.length; i++) {
var n = allNodes[i];

if (n instanceof XmlObjects.XElement) {
// XAttribute[]
var allAttributes = n.attributes(); // the attributes

console.log("I am an element with attributes: " + n.value);
else if (n instanceof XmlObjects.XComment) {
console.log("I am a comment: " + n.value);
else if (n instanceof XmlObjects.XText) {
console.log("I am a text." + n.value);
else if (n instanceof XmlObjects.XCData) {
console.log("I am a CDATA: " + n.value);

// create XML string
var xmlStr = rootElement.toString();