jsxml
jsxml is an XML library for javascript (and node)
单元测试
Install by NPM
npm install node-jsxml
How to use?
After add this library to your project, there will be a global object named jsxml.
in HTML file, import using <script> elements.
in Node, import using require
function.
const jsxml = ;
support AMD, CMD. Big thanks to TimSchlechter.
seajs;seajs;
var Namespace = jsxmlNamespace QName = jsxmlQName XML = jsxmlXML XMLList = jsxmlXMLList;
Here you go:
var xml = "<spring>" + "<list id='data'>" + "<element value='jsxml'/>" + "<element value='is'/>" + "<element value='an'/>" + "<element value='xml'/>" + "<element value='parser'/>" + "</list>" + "</spring>";
find special childs
var child = xml;
find all children by *
var children = xml;
print the xml string
console;
modify namespace
xml;xml;console;
find descendants nodes
var descendants = xml;
get all children
var children = xml;//orvar children = xml;
get text node
var text = xmltext;
get element node
var elements = xmlelements;
get comment node
var comments = xml;
get attribute
var attribute = xml;
get all attributes
var attributes = xmlattributes;
All methods above return an XML object or XMLList object, if you want to get the String type content, you should:
var xml = xmlContent; var attrValue = xml;//orvar attrValue = xml; var childA = xml;//orvar childA = xml;
If you want to modify the value, you should call method setValue:
var xml = "your xml string"; var attr= xml;attr; var childA = xml;childA;
You can regenerate the XML Content
var str = xml;
While dealing with a list of childs in XML tree, you should use XMLList API:
var list = xml;list;
Advanced topics
You can also add, retrieve or remove namespaces:
var xml = "your xml string";var ns = xml; var nsNew = "prefix" 'uri';xml;xml;
Bugs & Feedback
Please feel free report bugs or feature requests. You can send me private message on [github], or send me an email to: [colorhook@gmail.com]
License
jsxml is free to use under MIT license.