xast-util-from-xml
xast utility to parse from XML
Last updated 4 months ago by wooorm .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install xast-util-from-xml 
SYNC missed versions from official npm registry.

xast-util-from-xml

Build Coverage Downloads Size Sponsors Backers Chat

xast utility to parse from XML.

Install

npm:

npm install xast-util-from-xml

Use

Say we have the following XML file, example.xml:

<album id="123">
  <name>Born in the U.S.A.</name>
  <artist>Bruce Springsteen</artist>
  <releasedate>1984-04-06</releasedate>
</album>

And our script, example.js, looks as follows:

var fs = require('fs')
var fromXml = require('xast-util-from-xml')

var doc = fs.readFileSync('example.xml')

var tree = fromXml(doc)

console.log(tree)

Now, running node example yields (positional info removed for brevity):

{
  type: 'root',
  children: [
    {
      type: 'element',
      name: 'album',
      attributes: {id: '123'},
      children: [
        {type: 'text', value: '\n  '},
        {
          type: 'element',
          name: 'name',
          attributes: {},
          children: [{type: 'text', value: 'Born in the U.S.A.'}]
        },
        {type: 'text', value: '\n  '},
        {
          type: 'element',
          name: 'artist',
          attributes: {},
          children: [{type: 'text', value: 'Bruce Springsteen'}]
        },
        {type: 'text', value: '\n  '},
        {
          type: 'element',
          name: 'releasedate',
          attributes: {},
          children: [{type: 'text', value: '1984-04-06'}]
        },
        {type: 'text', value: '\n'}
      ]
    },
    {type: 'text', value: '\n'}
  ]
}

API

fromXml(doc)

Parse XML to a xast tree.

Parameters
doc

Value to parse (string or Buffer in UTF-8).

Returns

Root.

Security

XML can be a dangerous language: don’t trust user-provided data.

Related

Contribute

See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer

Current Tags

  • 1.0.0                                ...           latest (4 months ago)

1 Versions

  • 1.0.0                                ...           4 months ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 7
Dependencies (2)
Dev Dependencies (8)

Copyright 2014 - 2016 © taobao.org |