You are referencing 'fileName' as a string, but it should be a variable. So replace it to this:
var f = file.ReadFromFile(filename);
Also note variable names are case sensitive.
Then, check your file contents has xml first, use dlg.ShowMessage at various points, for example verify the path that is used, verify your file contains the xml. It can be difficult to debug in the script editor so doing this can help a lot.
I have not been following it closely because it really hasnt interested me but just my first thought is your making something extremely complicated that could be handled with simple actions and rules in SambaPOS. Instead your trying to script everything…
Sorry, I misread your script, o.toString() will not work as o is an XML object, not a string. The error message you posted is a generic one when you try to pass a non string to dlg.ShowMessage().
Try
var s = o.getElementByTagName('ds:DigestValue');
That may return an object, so I think you can try one of these:
It all points to the fact that may not be XML data there. Did you test the file name and that you have XML returned first? If you don’t do that, there is no point debugging further until you confirm your text from the file is actually loaded into f.
In the exemple of emre it is clear …
However in my xml file, I have a lot of:
<ext:xxxxx ...
and using the double-dot : is obviously not working, nor with the ’ caracter
var o = xml.Parse(f);
var r = o.Invoice.'ext:UBLExtensions'.'ext:UBLExtension'.'ext:ExtensionContent'.'ds:Signature'.'ds:SignedInfo'.'ds:Reference'.'ds:DigestValue'.Value;
To read some string in a text? cat filename | grep DigestValue | sed -e 's/^..ds:DigestValue\>//' | sed -e 's/\<DigestValue//'
and that’s done.
however if you don’t know how works the sambaPOS helper xml.Parse, you only can try …
There is no information on internet about sambaPOS helper xml.Parse
Actually I try with exemple of emre adding a ext:car in the xml string and cannot get an extract of car.color.value … so I think, I’ll not be able to do it that way.
Surely parsing returns an array the same as parsing json, if parsing is working but calling value is causing issues surely it has been converted to array without issue, unless I’m missing something.
Well, xml parsing is a bit opaque for me, so I used the strings.
function getXMLVal(settingname) {
var filename = getSettingVal('SFS_Path_gen')+"PARSE\\"+makeSFSFilename()+".xml";
var f = file.ReadFromFile(filename);
var r = findWord(f, 'ds:DigestValue');
return r;
}
// :) TextToLook, WordToFind :)
function findWord(ttl,wtf) {
var i, b, e = 0;
var r = "";
var vwtf = wtf+">";
i = ttl.indexOf(vwtf);
b = i + vwtf.length;
var vwtf = "</"+wtf;
i = ttl.indexOf(vwtf);
e = i;
var m = dlg.ShowMessage("b = "+b+" e = "+e+" i = "+i+" vwtf : "+vwtf);
for (i = b; i < e; i++) {
r = r + ttl[i];
}
return r;
}
And I have my DigestValue (or any other) from an xml file.
This isn’t really about the xml.Parse() helper at all. The function reads XML and returns an Object. That’s all it does. There is no other functionality to it.
var carColor = car.color.Value
That ^ “dot” notation is the JScript syntax used to read a value from an Object. Another way is:
var carColor = car["color"]["Value"]
Not sure what to say about the colons (:), but you will get errors because the JScript engine doesn’t understand what to do with them, but maybe try this: