Hi,
i want to import data from an xml file and im not beign able to import the data.
Im trying to use the XMLreader plugin but im not getting how to use the nodes it returns.
Can anyone give me some explanation of how to do this??
thanks in advance
pbakker wrote:Note that if your XML file starts with something like "<?xml version="1.0" encoding="UTF-8"?>", you need to first strip it off, because the JavaSCript XMl implementation doesn't consider that valid XML.
var $xml = myXmlString;
$xml = $xml.replace(/<\/?[^>]+(>|$)/g, function (strMatch, p1){return (/xml version/.test(strMatch)) ? '' : strMatch})
pbakker wrote:If you google for "e4x", which is the official name for the JavaScript XML implementation, you'll find quite a bit of information.
Paul
function testE4X() {
var file = plugins.file.showFileOpenDialog(1, null, false, ['XML files', 'xml'], null, 'Open XML File');
if (file) {
var txt = plugins.file.readTXTFile(file);
if (txt) {
txt = utils.stringTrim(txt.substring(txt.indexOf('\n')+1));
var xml = new XML(txt);
application.output(xml.salesorder);
}
}
}
mboegem wrote:pbakker wrote:Note that if your XML file starts with something like "<?xml version="1.0" encoding="UTF-8"?>", you need to first strip it off, because the JavaSCript XMl implementation doesn't consider that valid XML.
which can be easily done using replace like this.
- Code: Select all
var $xml = myXmlString;
$xml = $xml.replace(/<\/?[^>]+(>|$)/g, function (strMatch, p1){return (/xml version/.test(strMatch)) ? '' : strMatch})
Users browsing this forum: No registered users and 0 guests