|
| 1 | + |
| 2 | + |
| 3 | +Example |
| 4 | + |
| 5 | +```js |
| 6 | +const options = { |
| 7 | + preserveOrder: true, |
| 8 | + removeNSPrefix: false, // remove NS from tag name or attribute name if true |
| 9 | + stopNodes: [], //nested tags will not be parsed even for errors |
| 10 | + htmlEntities: false, |
| 11 | + tags:{ |
| 12 | + unpaired: [], |
| 13 | + nameFor:{ |
| 14 | + cdata: false, |
| 15 | + comment: false, |
| 16 | + text: '#text' |
| 17 | + }, |
| 18 | + separateTextProperty: false, |
| 19 | + //"join" only if preserveOrder: true |
| 20 | + valueParsers: ["trim","entities","join","boolean","number","currency","date"] |
| 21 | + }, |
| 22 | + attributes: { |
| 23 | + ignore: false, |
| 24 | + booleanType:true, |
| 25 | + entities: true, |
| 26 | + //"groupBy": "att" |
| 27 | + }, |
| 28 | + OutputBuilder: new JsObjOutputBuilder() |
| 29 | +}; |
| 30 | +const parser = new XMLParser(options); |
| 31 | +let result = parser.parse(xmlData, true); |
| 32 | +``` |
| 33 | + |
| 34 | +- You can build your own Output Builder. FXP provides 3 builders |
| 35 | + - JsObjOutputBuilder |
| 36 | + - JsArrBuilder |
| 37 | + - JsMinArrBuilder |
| 38 | +- You can control the sequence of value parsing for a tag or attribute |
| 39 | +- You can pass a string or bytes array as input. |
| 40 | + |
| 41 | +### Value Parser |
| 42 | +You can change the sequence of value parsers or remove one or provide your own parser to control the parsing. |
| 43 | + |
| 44 | +### Output builders |
| 45 | +You can use provided output builds or your own output builder. |
| 46 | + |
| 47 | +JsObjOutputBuilder |
| 48 | +```js |
| 49 | +{ |
| 50 | + "soap:Envelope": { |
| 51 | + "@_xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/", |
| 52 | + "soap:Body": { |
| 53 | + "rpt:loadReportFileResponseElem": { |
| 54 | + "@_xmlns:s": "http://bus.x.com/common/support/v1", |
| 55 | + "@_xmlns:rpt": "http://bus.x.com/service/statement/v1", |
| 56 | + "s:code": 0, |
| 57 | + "s:responseTime": 2588, |
| 58 | + "s:responseDbTime": 1893, |
| 59 | + "s:requestId": "6b408fd09eb211e7a0807e34820340ec", |
| 60 | + "s:route": "172.16.x.x:9192", |
| 61 | + "rpt:result": { |
| 62 | + "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>" |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +JsArrBuilder |
| 71 | +```js |
| 72 | +{ |
| 73 | + "tagname": "soap:Envelope", |
| 74 | + "child": [ |
| 75 | + { |
| 76 | + "tagname": "soap:Body", |
| 77 | + "child": [ |
| 78 | + { |
| 79 | + "tagname": "rpt:loadReportFileResponseElem", |
| 80 | + "child": [ |
| 81 | + { |
| 82 | + "tagname": "s:code", |
| 83 | + "child": [ |
| 84 | + { |
| 85 | + "#text": 0 |
| 86 | + } |
| 87 | + ] |
| 88 | + }, |
| 89 | + { |
| 90 | + "tagname": "s:responseTime", |
| 91 | + "child": [ |
| 92 | + { |
| 93 | + "#text": 2588 |
| 94 | + } |
| 95 | + ] |
| 96 | + }, |
| 97 | + { |
| 98 | + "tagname": "s:responseDbTime", |
| 99 | + "child": [ |
| 100 | + { |
| 101 | + "#text": 1893 |
| 102 | + } |
| 103 | + ] |
| 104 | + }, |
| 105 | + { |
| 106 | + "tagname": "s:requestId", |
| 107 | + "child": [ |
| 108 | + { |
| 109 | + "#text": "6b408fd09eb211e7a0807e34820340ec" |
| 110 | + } |
| 111 | + ] |
| 112 | + }, |
| 113 | + { |
| 114 | + "tagname": "s:route", |
| 115 | + "child": [ |
| 116 | + { |
| 117 | + "#text": "172.16.x.x:9192" |
| 118 | + } |
| 119 | + ] |
| 120 | + }, |
| 121 | + { |
| 122 | + "tagname": "rpt:result", |
| 123 | + "child": [ |
| 124 | + { |
| 125 | + "tagname": "rpt:file", |
| 126 | + "child": [ |
| 127 | + { |
| 128 | + "#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>" |
| 129 | + } |
| 130 | + ] |
| 131 | + } |
| 132 | + ] |
| 133 | + } |
| 134 | + ], |
| 135 | + ":@": { |
| 136 | + "@_xmlns:s": "http://bus.x.com/common/support/v1", |
| 137 | + "@_xmlns:rpt": "http://bus.x.com/service/statement/v1" |
| 138 | + } |
| 139 | + } |
| 140 | + ] |
| 141 | + } |
| 142 | + ], |
| 143 | + ":@": { |
| 144 | + "@_xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/" |
| 145 | + } |
| 146 | +} |
| 147 | +``` |
| 148 | + |
| 149 | +JsMinArrBuilder |
| 150 | +```js |
| 151 | +{ |
| 152 | + "soap:Envelope": [ |
| 153 | + { |
| 154 | + "soap:Body": [ |
| 155 | + { |
| 156 | + "rpt:loadReportFileResponseElem": [ |
| 157 | + { |
| 158 | + "s:code": [ |
| 159 | + { |
| 160 | + "#text": 0 |
| 161 | + } |
| 162 | + ] |
| 163 | + }, |
| 164 | + { |
| 165 | + "s:responseTime": [ |
| 166 | + { |
| 167 | + "#text": 2588 |
| 168 | + } |
| 169 | + ] |
| 170 | + }, |
| 171 | + { |
| 172 | + "s:responseDbTime": [ |
| 173 | + { |
| 174 | + "#text": 1893 |
| 175 | + } |
| 176 | + ] |
| 177 | + }, |
| 178 | + { |
| 179 | + "s:requestId": [ |
| 180 | + { |
| 181 | + "#text": "6b408fd09eb211e7a0807e34820340ec" |
| 182 | + } |
| 183 | + ] |
| 184 | + }, |
| 185 | + { |
| 186 | + "s:route": [ |
| 187 | + { |
| 188 | + "#text": "172.16.x.x:9192" |
| 189 | + } |
| 190 | + ] |
| 191 | + }, |
| 192 | + { |
| 193 | + "rpt:result": [ |
| 194 | + { |
| 195 | + "rpt:file": [ |
| 196 | + { |
| 197 | + "#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>" |
| 198 | + } |
| 199 | + ] |
| 200 | + } |
| 201 | + ] |
| 202 | + } |
| 203 | + ], |
| 204 | + ":@": { |
| 205 | + "@_xmlns:s": "http://bus.x.com/common/support/v1", |
| 206 | + "@_xmlns:rpt": "http://bus.x.com/service/statement/v1" |
| 207 | + } |
| 208 | + } |
| 209 | + ] |
| 210 | + } |
| 211 | + ], |
| 212 | + ":@": { |
| 213 | + "@_xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/" |
| 214 | + } |
| 215 | +} |
| 216 | +``` |
| 217 | + |
0 commit comments