@a-mehrabi/aranode-amqp-client
v1.0.0
Published
xml parser implementation for aranode flow engine.
Downloads
6
Readme
XML PARSER Module
xml parser implementation for aranode flow engine.
Table of Contents
Installation
To install this module in your aranode project, you just need to add the package using following command:
$ yarn add @a-mehrabi/aranode-xml-parser
After that, when you want to use it, you must include it in custom modules like the following:
path: .env
ARANODE_CUSTOM_MODULES=@a-mehrabi/aranode-xml-parser
Usage
For using xml encoder or decoder, you need to use encoder or decoder associated description:
- xml encoder flow description (xmlEncoder)
- xml decoder flow description (xmlDecoder)
xml encoder
xml encoder flow description enables you to define the xml encoder as a flow node, including indent, noArrayIndent config, etc.
xml encoder, encodes javascript literal object to xml string.
version: 1
kind: flow
name: flow-name
entryPoint: start
flow:
start:
transform:
path: 'dist/get-payload-transformer.js'
nextNode: initXmlEncoder
initXmlEncoder:
xmlEncoder:
headless: false
nextNode: checkPayload
checkPayload:
transform:
path: 'dist/check-payload-transformer.js'
terminal: true
xml decoder
xml decoder flow description enables you to define the xml decoder as a flow node.
xml decoder, decodes xml string to javascript literal object.
version: 1
kind: flow
name: flow-name
entryPoint: start
flow:
start:
transform:
path: 'dist/get-payload-transformer.js'
nextNode: initXmlDecoder
initXmlDecoder:
xmlDecoder:
explicitCharkey: false
nextNode: checkPayload
checkPayload:
transform:
path: 'dist/check-payload-transformer.js'
terminal: true
API
xmlEncoder
Type: flow description
Options:
attrkey (string), optional, default = '$'
Prefix that is used to access the attributes.
charkey (string), optional, default = '_'
Prefix that is used to access the character content.
rootName (string), optional
Root element name to be used in case explicitRoot is false or to override the root element name. (default root or the root key name)
doctype (any), optional, default = null
Optional DTD. Eg. {'ext': 'hello.dtd'}.
headless (boolean), optional, default = false
Omit the XML header.
allowSurrogateChars (boolean), optional, default = false
Allows using characters from the Unicode surrogate blocks.
cdata (boolean), optional, default = false
Wrap text nodes in instead of escaping when necessary. Does not add if it is not required.
xmllDecoder
Type: flow description
Options:
key (string), optional
attrkey (string), optional, default = '$'
Prefix that is used to access the attributes.
charkey (string), optional, default = '_'
Prefix that is used to access the character content.
explicitCharkey (boolean), optional, default = false
trim (boolean), optional, default = false
Trim the whitespace at the beginning and end of text nodes.
normalizeTags (boolean), optional, default = false
Normalize all tag names to lowercase.
normalize (boolean), optional, default = false
Trim whitespaces inside text nodes.
explicitRoot (boolean), optional, default = true
Set this if you want to get the root node in the resulting object.
explicitArray (boolean), optional, default = true
Always put child nodes in an array if true; otherwise an array is created only if there is more than one.
ignoreAttrs (boolean), optional, default = false
Ignore all XML attributes and only create text nodes.
mergeAttrs (boolean), optional, default = false
Merge attributes and child elements as properties of the parent,
instead of keying attributes off a child attribute object.
This option is ignored if ignoreAttrs is true.xmlns (boolean), optional, default = false
Give each element a field usually called '$ns' (the first character is the same as attrkey)
that contains its local name and namespace URI.explicitChildren (boolean), optional, default = false
Put child elements to separate property. Doesn't work with mergeAttrs = true.
If element has no children then "children" won't be created.childkey (string), optional, default = '$$'
Prefix that is used to access child elements if explicitChildren is set to true.
preserveChildrenOrder (boolean), optional, default = false
Modifies the behavior of explicitChildren so that the value of the "children" property becomes an ordered array.
When this is true, every node will also get a #name field whose value will correspond to the XML nodeName,
so that you may iterate the "children" array and still be able to determine node names.
The named (and potentially unordered) properties are also retained in this configuration at the same level as the ordered "children" array.charsAsChildren (boolean), optional, default = false
Determines whether chars should be considered children if explicitChildren is on.
includeWhiteChars (boolean), optional, default = false
Determines whether whitespace-only text nodes should be included.
async (boolean), optional, default = false
Should the callbacks be async? This might be an incompatible change if your code depends on sync execution of callbacks.
Future versions of xml2js might change this default, so the recommendation is to not depend on sync execution anyway.strict (boolean), optional, default = true
Set sax-js to strict or non-strict parsing mode.
Defaults to true which is highly recommended,
since parsing HTML which is not well-formed XML might yield just about anything.chunkSize (number), optional