<script type="text/x-red" data-template-name="xml"> <div class="form-row"> <label for="node-input-property"><i class="fa fa-ellipsis-h"></i> <span data-i18n="node-red:common.label.property"></span></label> <input type="text" id="node-input-property" style="width:70%;"/> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label> <input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name"> </div> <hr align="middle"/> <div class="form-row"> <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="_"> </div> </script> <script type="text/x-red" data-help-name="xml"> <p>Converts between an XML string and its JavaScript object representation, in either direction.</p> <h3>Inputs</h3> <dl class="message-properties"> <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> for more information.</dd> </dl> <h3>Details</h3> <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> </script> <script type="text/javascript"> RED.nodes.registerType('xml',{ category: 'function', color:"#DEBD5C", defaults: { name: {value:""}, property: {value:"payload",required:true}, attr: {value:""}, chr: {value:""} }, inputs:1, outputs:1, icon: "parser-xml.png", label: function() { return this.name||"xml"; }, labelStyle: function() { return this.name?"node_label_italic":""; }, oneditprepare: function() { if (this.property === undefined) { $("#node-input-property").val("payload"); } $("#node-input-property").typedInput({default:'msg',types:['msg']}); } }); </script>