Coder Social home page Coder Social logo

petuomin / jxon Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tyrasd/jxon

0.0 1.0 0.0 139 KB

lossless JavaScript XML Object Notation

Home Page: https://developer.mozilla.org/en-US/docs/JXON

License: GNU General Public License v3.0

JavaScript 100.00%

jxon's Introduction

JXON

A complete, bidirectional, JXON (lossless JavaScript XML Object Notation) library. Works like nodejs module, AMD module or creates global window.JXON object.

Implementation of Mozilla's JXON code. Head over to MDN for Documentation.

Build Status

Without changing the configuration, the library will work as original implementation.

JXON.config(cnf)

Overrides default configuration properties

  • cnf - Object with configuration properties.

Example:

JXON.config({
  valueKey: '_',                // default: 'keyValue'
  attrKey: '$',                 // default: 'keyAttributes'
  attrPrefix: '$',              // default: '@'
  lowerCaseTags: false,         // default: true
  trueIsEmpty: false,           // default: true
  autoDate: false,              // default: true
  ignorePrefixedNodes: false,   // default: true
  parseValues: false            // default: true
});

Conversion example:

{name: 'myportal'} 
<name>myportal</name>

{user: {
    username: 'testUser1',
    password: 'yolo',
    enabled: true
}}
<user>
  <username>testUser1</username>
  <password>yolo</password>
  <enabled>true</enabled>
</user>

{tag: {
    $type: 'regular'
    $blacklist: false
    _: 'Backbase'
}}
<tag type="regular" blacklist="false">Backbase</tag>

{dogs: {
    name: ['Charlie', {$nick: 'yes', _:'Mad Max'}]
}}
<dogs>
    <name>Charlie</name>
    <name nick="yes">Mad Max</name>
</dogs>

JXON.stringToJs(xmlString)

Converts XML string to JS object.

  • xmlString - XML string to convert to JXON notation JS object

JXON.jsToString(obj)

Converts JS object to XML string.

  • obj - JS object in JXON notation to convert to XML string

JXON.build(xmlDocument, verbosity, freeze, nestedAttributes)

Converts XML document to JS object. Alias: JXON.xmlToJs

  • xmlDocument - The XML document to be converted into JavaScript Object.
  • verbosity - Optional verbosity level of conversion, from 0 to 3. It is almost equivalent to our algorithms from #4 to #1 (default value is 1, which is equivalent to the algorithm #3).
  • freeze - Optional boolean expressing whether the created object must be freezed or not (default value is false).
  • nestedAttributes - Optional boolean expressing whether the the nodeAttributes must be nested into a child-object named keyAttributes or not (default value is false for verbosity levels from 0 to 2; true for verbosity level 3).

Example:

var myObject = JXON.build(xmlDoc);

JXON.unbuild(obj, namespaceURI, qualifiedNameStr, documentType)

Converts JS object to XML document. Alias: JXON.jsToXml

  • obj - The JavaScript Object from which you want to create your XML Document.
  • namespaceURI - Optional DOMString containing the namespace URI of the document to be created, or null if the document doesn't belong to one.
  • qualifiedNameStr - Optional DOMString containing the qualified name, that is an optional prefix and colon plus the local root element name, of the document to be created.
  • documentType - Optional DocumentType of the document to be created. It defaults to null.

Example:

var myObject = JXON.unbuild(myObject);

JXON.stringToXml(xmlString)

Implementation of DOMParser.parseFromString, converts string to XML document.

  • xmlString - XML string to convert to XML document

JXON.xmlToString(xmlObj)

Implementation of XMLSerializer.serializeToString, converts XML document to string.

  • xmlObj - XML document to convert to XML string

jxon's People

Contributors

tyrasd avatar igord avatar petuomin avatar

Watchers

James Cloos 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.