1.0.43 • Published 8 months ago
xml-toolkit v1.0.43
node-xml-toolkit
XML parsers (synchronous, streaming), marshaller, SOAP adapters (1.1, 1.2)
Installation
npm i xml-toolkit
Using
const fs = require ('fs')
const {XMLParser} = require ('xml-toolkit')
const xml = fs.readFileSync ('doc.xml')
const parser = new XMLParser ({...options})
const document = parser.process (xml)
for (const element of document.detach ().children) {
console.log (element.attributes)
}
- Reading a Record List, streaming mode
const {XMLReader, XMLNode} = require ('xml-toolkit')
const records = new XMLReader ({
filterElements : 'Record',
map : XMLNode.toObject ({})
}).process (xmlSource)
// ...then:
// await someLoader.load (records)
// ...or
// for await (const record of records) { // pull parser mode
// ...or
// records.on ('error', e => console.log (e))
// records.pipe (nextStream)
// ...or
// records.on ('error', e => console.log (e))
// records.on ('data', record => doSomethingWith (record))
- Getting a Single Element, streaming mode
const {XMLReader, XMLNode} = require ('xml-toolkit')
const data = await new XMLReader ({
filterElements : 'MyElementName',
map : XMLNode.toObject ({})
}).process (xmlSource).findFirst ()
const {XMLReader} = require ('xml-toolkit')
let xmlResult = ''; for await (const node of new XMLReader ().process (xmlSource)) xmlResult +=
node.isCharacters && node.parent.localName === 'ThePlaceHolder' ? id :
node.xml
const {XMLSchemata} = require ('xml-toolkit')
const data = {ExportDebtRequestsResponse: {
"request-data": {
// ...
}
}
const xs = new XMLSchemata ('xs.xsd')
const xml = xs.stringify (data)
/* result:
<ns0:ExportDebtRequestsResponse xmlns:ns0="urn:...">
<ns0:request-data>
<!-- ... and so on ... -->
*/
const http = require ('http')
const {SOAP11, SOAP12} = require ('xml-toolkit')
const soap = new SOAP11 ('their.wsdl') // or SOAP12
const {method, headers, body} = soap.http ({RequestElementNameOfTheirs: {amount: '0.01'}})
const rq = http.request (endpointURL, {method, headers})
rq.write (body)
- Implementing a SOAP service
const {XMLSchemata, SOAP11, SOAP12, SOAPFault} = require ('xml-toolkit')
const SOAP = SOAP11 // or SOAP12
const xs = new XMLSchemata (`myService.wsdl`)
let body, statusCode; try {
body = xs.stringify (myMethod (/*...*/))
statusCode = 200
}
catch (x) {
body = new SOAPFault (x)
statusCode = 500
}
rp.writeHead (statusCode, {
'Content-Type': SOAP.contentType,
})
const xml = SOAP.message (body)
rp.end (xml)
For more information, see wiki docs.
1.0.37
9 months ago
1.0.39
9 months ago
1.0.38
9 months ago
1.0.40
8 months ago
1.0.43
8 months ago
1.0.42
8 months ago
1.0.41
8 months ago
1.0.36
2 years ago
1.0.35
2 years ago
1.0.34
2 years ago
1.0.19
3 years ago
1.0.18
3 years ago
1.0.17
3 years ago
1.0.16
3 years ago
1.0.22
3 years ago
1.0.21
3 years ago
1.0.20
3 years ago
1.0.26
3 years ago
1.0.25
3 years ago
1.0.24
3 years ago
1.0.23
3 years ago
1.0.29
3 years ago
1.0.28
3 years ago
1.0.27
3 years ago
1.0.33
2 years ago
1.0.32
2 years ago
1.0.31
2 years ago
1.0.30
2 years ago
1.0.15
3 years ago
1.0.14
3 years ago
1.0.13
3 years ago
1.0.12
3 years ago
1.0.11
3 years ago
1.0.9
3 years ago
1.0.8
3 years ago
1.0.7
3 years ago
1.0.6
3 years ago
1.0.10
3 years ago
1.0.5
3 years ago
1.0.4
3 years ago
1.0.3
3 years ago
1.0.2
3 years ago
1.0.1
3 years ago
1.0.0
3 years ago
0.0.9
3 years ago
0.0.8
3 years ago
0.0.5
4 years ago
0.0.4
4 years ago
0.0.7
4 years ago
0.0.6
4 years ago
0.0.3
4 years ago
0.0.1
4 years ago