diff --git a/xmltojson/xmltojson-tests.ts b/xmltojson/xmltojson-tests.ts new file mode 100644 index 000000000..f89093625 --- /dev/null +++ b/xmltojson/xmltojson-tests.ts @@ -0,0 +1,36 @@ +/// + +import * as xmltojson from 'xmltojson'; + +//Set options +var options: xmltojson.Options = { + mergeCDATA: true, + grokAttr: true, + grokText: true, + normalize: true, + xmlns: true, + namespaceKey: '_ns', + textKey: '_text', + valueKey: '_value', + attrKey: '_attr', + cdataKey: '_cdata', + attrsAsObject: true, + stripAttrPrefix: true, + stripElemPrefix: true, + childrenAsArray: true +} + +//Validate parseString(xmlString, opt) +var xmlString: string = 'It Works!'; +var parsedXmlString: Object = xmltojson.parseString(xmlString, options); + +console.log(JSON.stringify(parsedXmlString)); + +//Validate stringToXml(xmlString) and parseXml(oXMLParent, opt) +var oXMLParent: Document = xmltojson.stringToXml(xmlString); + +console.log(oXMLParent.getElementsByName('a').item(0).textContent); + +var parsedXmlString2: Object = xmltojson.parseXml(oXMLParent, options); + +console.log(JSON.stringify(parsedXmlString2)); diff --git a/xmltojson/xmltojson.d.ts b/xmltojson/xmltojson.d.ts new file mode 100644 index 000000000..c70232fa1 --- /dev/null +++ b/xmltojson/xmltojson.d.ts @@ -0,0 +1,34 @@ +// Type definitions for xmltojson +// Project: https://github.com/metatribal/xmlToJSON +// Definitions by: Travis Crowe http://github.com/traviscrowe +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module 'xmltojson' { + + export = xmltojson; + + module xmltojson { + function grokType(sValue: any): any; + function parseString(xmlString: string, opt: Options): Object; + function parseXml(oXMLParent: Document, opt: Options): Object; + function xmlToString(xmlDoc: Document): string; + function stringToXml(xmlString: string): Document; + + interface Options { + mergeCDATA?: boolean, + grokAttr?: boolean, + grokText?: boolean, + normalize?: boolean, + xmlns?: boolean, + namespaceKey?: string, + textKey?: string, + valueKey?: string, + attrKey?: string, + cdataKey?: string, + attrsAsObject?: boolean, + stripAttrPrefix?: boolean, + stripElemPrefix?: boolean, + childrenAsArray?: boolean + } + } +}