0.0.6 • Published 1 year ago

@mycore-org/xml-json-api v0.0.6

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
1 year ago

xml-json-api

A simple collection of functions to convert the dom API to simple Javascript Objects vice versa and helper functions to use them in modern frontend frameworks.

Usage

dom2XElement

Code:

import {dom2XElement} from "xml-json-api";

const xml = "<xml>one does not <b>simply</b> convert xml</xml>";
const xmlDocument = new window.DOMParser().parseFromString(xml, "application/xml");
const root = xmlDocument.children.item(0);
const result = dom2XElement(root);

console.log(JSON.stringify(result, null, 2));

Result:

{
   "type": "Element",
   "content": [
     {
       "type": "Text",
       "text": "one does not "
     },
     {
       "type": "Element",
       "content": [
         {
           "type": "Text",
           "text": "simply"
         }
       ],
       "name": "b"
     },
     {
       "type": "Text",
       "text": " convert xml"
     }
   ],
   "name": "xml"
 }
0.0.6

1 year ago

0.0.5

2 years ago

0.0.4

2 years ago