-
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
364e327
commit ba5f35e
Showing
30 changed files
with
2,183 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
|
||
|
||
Example | ||
|
||
```js | ||
const options = { | ||
preserveOrder: true, | ||
removeNSPrefix: false, // remove NS from tag name or attribute name if true | ||
stopNodes: [], //nested tags will not be parsed even for errors | ||
htmlEntities: false, | ||
tags:{ | ||
unpaired: [], | ||
nameFor:{ | ||
cdata: false, | ||
comment: false, | ||
text: '#text' | ||
}, | ||
separateTextProperty: false, | ||
//"join" only if preserveOrder: true | ||
valueParsers: ["trim","entities","join","boolean","number","currency","date"] | ||
}, | ||
attributes: { | ||
ignore: false, | ||
booleanType:true, | ||
entities: true, | ||
//"groupBy": "att" | ||
}, | ||
OutputBuilder: new JsObjOutputBuilder() | ||
}; | ||
const parser = new XMLParser(options); | ||
let result = parser.parse(xmlData, true); | ||
``` | ||
|
||
- You can build your own Output Builder. FXP provides 3 builders | ||
- JsObjOutputBuilder | ||
- JsArrBuilder | ||
- JsMinArrBuilder | ||
- You can control the sequence of value parsing for a tag or attribute | ||
- You can pass a string or bytes array as input. | ||
|
||
### Value Parser | ||
You can change the sequence of value parsers or remove one or provide your own parser to control the parsing. | ||
|
||
### Output builders | ||
You can use provided output builds or your own output builder. | ||
|
||
JsObjOutputBuilder | ||
```js | ||
{ | ||
"soap:Envelope": { | ||
"@_xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/", | ||
"soap:Body": { | ||
"rpt:loadReportFileResponseElem": { | ||
"@_xmlns:s": "http://bus.x.com/common/support/v1", | ||
"@_xmlns:rpt": "http://bus.x.com/service/statement/v1", | ||
"s:code": 0, | ||
"s:responseTime": 2588, | ||
"s:responseDbTime": 1893, | ||
"s:requestId": "6b408fd09eb211e7a0807e34820340ec", | ||
"s:route": "172.16.x.x:9192", | ||
"rpt:result": { | ||
"rpt:file": "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap:Body>\n <rpt:loadReportFileResponseElem\n xmlns:s=\"http://bus.x.com/common/support/v1\"\n xmlns:rpt=\"http://bus.x.com/service/statement/v1\">\n <s:code>0</s:code>\n <s:responseTime>2588</s:responseTime>\n <s:responseDbTime>1893</s:responseDbTime>\n <s:requestId>6b408fd09eb211e7a0807e34820340ec</s:requestId>\n <s:route>172.16.x.x:9192</s:route>\n <rpt:result>\n <rpt:file></rpt:file>\n </rpt:result>\n </rpt:loadReportFileResponseElem>\n </soap:Body>\n</soap:Envelope>" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
JsArrBuilder | ||
```js | ||
{ | ||
"tagname": "soap:Envelope", | ||
"child": [ | ||
{ | ||
"tagname": "soap:Body", | ||
"child": [ | ||
{ | ||
"tagname": "rpt:loadReportFileResponseElem", | ||
"child": [ | ||
{ | ||
"tagname": "s:code", | ||
"child": [ | ||
{ | ||
"#text": 0 | ||
} | ||
] | ||
}, | ||
{ | ||
"tagname": "s:responseTime", | ||
"child": [ | ||
{ | ||
"#text": 2588 | ||
} | ||
] | ||
}, | ||
{ | ||
"tagname": "s:responseDbTime", | ||
"child": [ | ||
{ | ||
"#text": 1893 | ||
} | ||
] | ||
}, | ||
{ | ||
"tagname": "s:requestId", | ||
"child": [ | ||
{ | ||
"#text": "6b408fd09eb211e7a0807e34820340ec" | ||
} | ||
] | ||
}, | ||
{ | ||
"tagname": "s:route", | ||
"child": [ | ||
{ | ||
"#text": "172.16.x.x:9192" | ||
} | ||
] | ||
}, | ||
{ | ||
"tagname": "rpt:result", | ||
"child": [ | ||
{ | ||
"tagname": "rpt:file", | ||
"child": [ | ||
{ | ||
"#text": "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap:Body>\n <rpt:loadReportFileResponseElem\n xmlns:s=\"http://bus.x.com/common/support/v1\"\n xmlns:rpt=\"http://bus.x.com/service/statement/v1\">\n <s:code>0</s:code>\n <s:responseTime>2588</s:responseTime>\n <s:responseDbTime>1893</s:responseDbTime>\n <s:requestId>6b408fd09eb211e7a0807e34820340ec</s:requestId>\n <s:route>172.16.x.x:9192</s:route>\n <rpt:result>\n <rpt:file></rpt:file>\n </rpt:result>\n </rpt:loadReportFileResponseElem>\n </soap:Body>\n</soap:Envelope>" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
":@": { | ||
"@_xmlns:s": "http://bus.x.com/common/support/v1", | ||
"@_xmlns:rpt": "http://bus.x.com/service/statement/v1" | ||
} | ||
} | ||
] | ||
} | ||
], | ||
":@": { | ||
"@_xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/" | ||
} | ||
} | ||
``` | ||
|
||
JsMinArrBuilder | ||
```js | ||
{ | ||
"soap:Envelope": [ | ||
{ | ||
"soap:Body": [ | ||
{ | ||
"rpt:loadReportFileResponseElem": [ | ||
{ | ||
"s:code": [ | ||
{ | ||
"#text": 0 | ||
} | ||
] | ||
}, | ||
{ | ||
"s:responseTime": [ | ||
{ | ||
"#text": 2588 | ||
} | ||
] | ||
}, | ||
{ | ||
"s:responseDbTime": [ | ||
{ | ||
"#text": 1893 | ||
} | ||
] | ||
}, | ||
{ | ||
"s:requestId": [ | ||
{ | ||
"#text": "6b408fd09eb211e7a0807e34820340ec" | ||
} | ||
] | ||
}, | ||
{ | ||
"s:route": [ | ||
{ | ||
"#text": "172.16.x.x:9192" | ||
} | ||
] | ||
}, | ||
{ | ||
"rpt:result": [ | ||
{ | ||
"rpt:file": [ | ||
{ | ||
"#text": "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap:Body>\n <rpt:loadReportFileResponseElem\n xmlns:s=\"http://bus.x.com/common/support/v1\"\n xmlns:rpt=\"http://bus.x.com/service/statement/v1\">\n <s:code>0</s:code>\n <s:responseTime>2588</s:responseTime>\n <s:responseDbTime>1893</s:responseDbTime>\n <s:requestId>6b408fd09eb211e7a0807e34820340ec</s:requestId>\n <s:route>172.16.x.x:9192</s:route>\n <rpt:result>\n <rpt:file></rpt:file>\n </rpt:result>\n </rpt:loadReportFileResponseElem>\n </soap:Body>\n</soap:Envelope>" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
":@": { | ||
"@_xmlns:s": "http://bus.x.com/common/support/v1", | ||
"@_xmlns:rpt": "http://bus.x.com/service/statement/v1" | ||
} | ||
} | ||
] | ||
} | ||
], | ||
":@": { | ||
"@_xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/" | ||
} | ||
} | ||
``` | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const XMLParser = require("../../src/v5/XMLParser"); | ||
const JsObjOutputBuilder = require("../../src/v5/OutputBuilders/JsObjBuilder"); | ||
const JsArrBuilder = require("../../src/v5/OutputBuilders/JsArrBuilder"); | ||
const JsMinArrBuilder = require("../../src/v5/OutputBuilders/JsMinArrBuilder"); | ||
|
||
const fs = require("fs"); | ||
const path = require("path"); | ||
const fileNamePath = path.join(__dirname, "../assets/ptest.xml");//with CDATA | ||
// const fileNamePath = path.join(__dirname, "../assets/ptest_with_prolog.xml");//with CDATA | ||
// const fileNamePath = path.join(__dirname, "../assets/sample.xml");//1.5k | ||
// const fileNamePath = path.join(__dirname, "../assets/midsize.xml");//13m | ||
// const fileNamePath = path.join(__dirname, "../assets/large.xml");//98m | ||
const xmlData = fs.readFileSync(fileNamePath).toString(); | ||
|
||
describe("XMLParser Entities", function() { | ||
|
||
it("should parse", function() { | ||
|
||
const options = { | ||
attributes: { | ||
ignore: false, | ||
booleanType:true | ||
}, | ||
OutputBuilder: new JsMinArrBuilder() | ||
}; | ||
const parser = new XMLParser(options); | ||
let result = parser.parse(xmlData); | ||
|
||
console.log(JSON.stringify(result,null,4)); | ||
// expect(result).toEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
modules.export = { | ||
"<" : "<", //tag start | ||
">" : ">", //tag end | ||
"/" : "/", //close tag | ||
"!" : "!", //comment or docttype | ||
"!--" : "!--", //comment | ||
"-->" : "-->", //comment end | ||
"?" : "?", //pi | ||
"?>" : "?>", //pi end | ||
"?xml" : "?xml", //pi end | ||
"![" : "![", //cdata | ||
"]]>" : "]]>", //cdata end | ||
"[" : "[", | ||
"-" : "-", | ||
"D" : "D", | ||
} |
Oops, something went wrong.