I'm pretty new to node red, and I'm trying to parse an XML file retrieved from HTTP. It's from a lightening detector. I just want to extract a few items and place them in a database, but the XML converter errors out.
Flow and XML are pasted in below.
When I get the XML and pass it directly to the XML converter, I got this error:
Error: Non-whitespace before first tag.Line: 0Column: 1Char: �
I added a change to remove the two characters at the beginning.
Now the XML converter returns Error: Unencoded <Line: 0Column: 2Char:
Oddly if I copy the output from the debug window directly into an inject string, it works perfectly.
Help?
The URL is: http://ccofmobile.thormobile14.net/AL0024.xml
Here's the flow:
[{"id":"4632da77.b89094","type":"tab","label":"Lightening Data","disabled":false,"info":""},{"id":"8a4c73b4.a0395","type":"http request","z":"4632da77.b89094","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"http://ccofmobile.thormobile14.net/AL0024.xml","tls":"","persist":false,"proxy":"","authType":"","x":290,"y":60,"wires":[["482ae5d6.04da0c"]]},{"id":"50bdbdf2.d0c424","type":"debug","z":"4632da77.b89094","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":710,"y":220,"wires":[]},{"id":"db7af6bf.0b2f38","type":"inject","z":"4632da77.b89094","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":60,"wires":[["8a4c73b4.a0395"]]},{"id":"31743a29.79ec76","type":"xml","z":"4632da77.b89094","name":"","property":"payload","attr":"","chr":"","x":470,"y":220,"wires":[["50bdbdf2.d0c424"]]},{"id":"482ae5d6.04da0c","type":"change","z":"4632da77.b89094","name":"Remove Bad Chars","rules":[{"t":"change","p":"payload","pt":"msg","from":"��","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":150,"y":220,"wires":[["31743a29.79ec76"]]},{"id":"6a17140f.44280c","type":"inject","z":"4632da77.b89094","name":"Inject xml","topic":"","payload":"<?xml version=\"1.0\" encoding=\"utf-16\" standalone=\"yes\"?><loadmovie> <moviename>ThorNet</moviename> <thordata> <displayname>Country Club of Mobile</displayname> <rawstring>;2011301000710000000B25001OAL002400.</rawstring> <localtime>02:39:36 AM 06/01/2020</localtime> <emergencystate>None</emergencystate> <sirenstate>NotAvailable</sirenstate> <testresult>Pass</testresult> <testcode>B</testcode> <testfailcount>0</testfailcount> <unitname>L75</unitname> <unitcode>7</unitcode> <range>12</range> <stringrevision>2</stringrevision> <chiprevision>O</chiprevision> <revisionfield>1O</revisionfield> <switch>Front</switch> <switchvalue>2</switchvalue> <isatminingsite>False</isatminingsite> <isoldunit>False</isoldunit> <uniqueid>AL0024</uniqueid> <lightningalert>Unknown</lightningalert> <ad>0</ad> <di>0.0</di> <lhl>0</lhl> <fcc>0</fcc> <fccrate>0</fccrate> <energypolarity>+</energypolarity> <energylevel>275</energylevel> <latitude>30.6873</latitude> <longitude>88.15454</longitude> <latdirection>N</latdirection> <londirection>W</londirection> <sensortype>Unknown</sensortype> <sensorside>Left</sensorside> <isdataold>False</isdataold> </thordata></loadmovie>","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":400,"wires":[["31743a29.79ec76"]]}]
The XML it returns:
<?xml version="1.0" encoding="utf-16" standalone="yes"?><loadmovie> <moviename>ThorNet</moviename> <thordata> <displayname>Country Club of Mobile</displayname> <rawstring>;2011301000710000000B25001OAL002400.</rawstring> <localtime>02:39:36 AM 06/01/2020</localtime> <emergencystate>None</emergencystate> <sirenstate>NotAvailable</sirenstate> <testresult>Pass</testresult> <testcode>B</testcode> <testfailcount>0</testfailcount> <unitname>L75</unitname> <unitcode>7</unitcode> <range>12</range> <stringrevision>2</stringrevision> <chiprevision>O</chiprevision> <revisionfield>1O</revisionfield> <switch>Front</switch> <switchvalue>2</switchvalue> <isatminingsite>False</isatminingsite> <isoldunit>False</isoldunit> <uniqueid>AL0024</uniqueid> <lightningalert>Unknown</lightningalert> <ad>0</ad> <di>0.0</di> <lhl>0</lhl> <fcc>0</fcc> <fccrate>0</fccrate> <energypolarity>+</energypolarity> <energylevel>275</energylevel> <latitude>30.6873</latitude> <longitude>88.15454</longitude> <latdirection>N</latdirection> <londirection>W</londirection> <sensortype>Unknown</sensortype> <sensorside>Left</sensorside> <isdataold>False</isdataold> </thordata></loadmovie>