Giter VIP home page Giter VIP logo

stablexml's Introduction

StableXML

Build Status | Test Coverage Report

Authors

This library was written by Jake Wood and James Steinberg for a Software Development (CS 6515) class at Northeastern University.

Summary

This Node.js module parses an XML string, but also maintains the order of the nodes. It uses a data format loosely based on xml2js, and uses SAX for the actual XML parsing.

Warning: this library was written specifically for an academic class. It does not support all features of XML, as these particular features were not needed for the class. For example, the following XML will parse, but data will be lost:

<test>1234</test>

In this example, the "1234" will be lost.

Development on this library might continue to support all of XML. We shall see. Feel free to fork and submit merge requests if you want to add this functionality.

Example

Suppose you are given the following XML input:

<foo>
    <bar baz="abc" />
    <bar abc="123" />
</foo>

This will create a JavaScript object that looks like this:

[
	{
		foo:
		{
            _: [
            {
            	bar:
            	{
	            	$: {
	            		baz: "abc"
	            	}
            },
            {
            	bar:
            	{
            		$: {
            			abc: "123"
            		}
            	}
            }
            ]
        }
    }
]

Obviously, these objects are very large/deep. We're very sorry about that, but it was the best way we could write the XML parser (quickly) to be sensitive to the ordering of the XML nodes.

Another example:

<state>
	<board>
		<tile row="A" column="1" />
	</board>
</state>

This will produce:

[
	{
		state:
		{
			_:
			[
				{
					board:
					{
						_:
						[
							{
								tile:
								{
									$:
									{
										row: "A",
										column: "1"
									}
								}
							}
						]
					}
				}
			]
		}
	}
]

These two examples lead to a common pattern, explained below using our data types.

Data Types

Node

A node is represented by:

{
	foo:
	{
		$: Attributes
		_: Array[Node]
	}
}

Where "foo" can be any arbitrary XML tag name.

Attributes

Attributes is either undefined or an associative JavaScript object containing the keys and values of the attributes of a true XML node.

Questions?

Feel free to open an issue on GitHub if you spot any issues or have questions.

stablexml's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.