0.0.8 • Published 10 years ago

xml.js v0.0.8

Weekly downloads
81
License
-
Repository
github
Last release
10 years ago

XML.js

What for?

XML.js provides helper functions for XML manipulation, including conversion of documents into JXON objects. It is built on top of xmldom & xpath modules and brings common XML-related features together into a simplistic API.

API

XML#parse

function parse(text) { ... //-> DOMDocument

XML#load

function load(file, [convert:false]) { ... //-> DOMDocument

XML#serialize

function serialize(node) { ... //-> String

XML#query

function query(node, expression, resolver) { ... //-> [Node]

####Example

XML.query(catalog, "//book[1]");
XML.query(response, "//here:contact[1]",  {"here": "http://being.here/"});

JXON

convert

function convert(node, [compact:true]) { ... //-> {Object}

####Example Given document is the following:

<contact firstName="George" lastName="Cartier">
    <notes>
        <![CDATA[
            Will call back tomorrow.
        ]]>
    </notes>
</contact>

Resulting JXON object, converted with JXON.convert(document), would be:

{
	"contact": {
		"firstName": "George",
		"lastName": "Cartier",
		"*": {
			"notes": {
				"*": {
					"#D": "Will call back tomorrow."
				}
			}
		}
	}
}

compact

function compact(object) { ... //-> {Object}

####Example When not compacted, previous result would be the following, which could be compacted afterwards with JXON#compact:

{
	"contact": {
		"@firstName": "George",
		"@lastName": "Cartier",
		"children": [
			{
				"#TEXT": "\n            "
			},
			{
				"notes": {
					"children": [
						{
							"#TEXT": "\n                "
						},
						{
							"#CDATA": "\n                    Will call back tomorrow.\n                "
						},
						{
							"#TEXT": "\n            "
						}
					]
				}
			},
			{
				"#TEXT": "\n        "
			}
		]
	}
}

More?

Please have a look to the test fixtures!

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago