2014-04-29 18:01:30 +02:00
< script type = "text/x-red" data-template-name = "xml" >
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-name" > < i class = "fa fa-tag" > < / i > < span data-i18n = "common.label.name" > < / span > < / label >
2016-06-27 00:48:59 +02:00
< input type = "text" id = "node-input-name" data-i18n = "[placeholder]common.label.name" >
2014-04-29 18:01:30 +02:00
< / div >
2017-05-23 10:35:37 +02:00
< hr align = "middle" / >
< div class = "form-row" >
2017-05-23 15:18:09 +02:00
< label style = "width:100%; border-bottom: 1px solid #eee;" > < span data-i18n = "xml.label.x2o" > < / span > < / label >
< / div >
< div class = "form-row" style = "padding-left: 20px;" >
< label style = "width:250px;" for = "node-input-attr" data-i18n = "xml.label.represent" > < / label > < input type = "text" id = "node-input-attr" style = "text-align:center; width:40px" placeholder = "$" >
< / div >
< div class = "form-row" style = "padding-left: 20px;" >
< label style = "width:250px;" for = "node-input-chr" data-i18n = "xml.label.prefix" > < / label > < input type = "text" id = "node-input-chr" style = "text-align:center; width:40px" placeholder = "_" >
2014-12-15 18:05:18 +01:00
< / div >
2014-04-29 18:01:30 +02:00
< / script >
< script type = "text/x-red" data-help-name = "xml" >
2017-05-23 15:18:09 +02:00
< p > Converts between an XML string and its JavaScript object representation, in either direction.< / p >
2017-04-25 22:47:58 +02:00
< h3 > Inputs< / h3 >
< dl class = "message-properties" >
2017-05-23 15:18:09 +02:00
< dt > payload< span class = "property-type" > object | string< / span > < / dt >
< dd > A JavaScript object or XML string.< / dd >
< / dl >
< h3 > Outputs< / h3 >
< dl class = "message-properties" >
< dt > payload< span class = "property-type" > object | string< / span > < / dt >
< dd >
< ul >
< li > If the input is a string it tries to parse it as XML and creates a JavaScript object.< / li >
< li > If the input is a JavaScript object it tries to build an XML string.< / li >
< / ul >
< / dd >
< dt class = "optional" > options < span class = "property-type" > object< / span > < / dt >
< dd > This optional property can be used to pass in any of the options supported by the underlying
library used to convert to and from XML. See < a href = "https://github.com/Leonidas-from-XIV/node-xml2js/blob/master/README.md#options" target = "_blank" > the xml2js docs< / a >
2017-04-25 22:47:58 +02:00
for more information.< / dd >
< / dl >
< h3 > Details< / h3 >
2017-05-23 15:18:09 +02:00
< p > When converting between XML and an object, any XML attributes are added as a property named < code > $< / code > by default.
Any text content is added as a property named < code > _< / code > . These property names can be specified in the node configuration.< / p >
< p > For example, the following XML will be converted as shown:< / p >
< pre > < p class="tag"> Hello World< /p> < / pre >
< pre > {
"p": {
"$": {
"class": "tag"
},
"_": "Hello World"
}
}< / pre >
2014-04-29 18:01:30 +02:00
< / script >
< script type = "text/javascript" >
RED.nodes.registerType('xml',{
category: 'function',
color:"#DEBD5C",
defaults: {
2015-02-10 17:55:50 +01:00
name: {value:""},
2015-09-26 14:46:35 +02:00
attr: {value:""},
chr: {value:""}
2014-04-29 18:01:30 +02:00
},
inputs:1,
outputs:1,
2016-06-12 23:37:38 +02:00
icon: "parser-xml.png",
2014-04-29 18:01:30 +02:00
label: function() {
return this.name||"xml";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
}
});
< / script >