JScript & Helper to extract xml value

Hi,

I have an xml file from which I would like to extract the digest value (and print that value on the Bill).

<ds:DigestValue>ZZrU7/ViT1/XyPE/OkXDMwpulKs=</ds:DigestValue>

So using

  • var f = file.ReadFromFile(fileName)
  • var o = xml.Parse(xmlContent) (xmlContent = f ?)
  • return o.ds.DigestValue (= what I am looking for ?)

Is this like that that I have to proceed?

Thanks,

Marc

xml file:
20528172777-03-B001-15.zip (3.8 KB)

Error when getXMLVal(settingname) invoked at linexml.Parse:

This forum about SambaPOS. I think stackoverflow is a good place to find your answer.

HELPERS are not enhencements included in SambaPOS by emre?
That’s why I was asking here.

Yes but still your question not about with SambaPOS. Can you extract that normal web site ?

it’s all about html on internet … :confused:

So i think this is not about SambaPOS.

Can’t find any information about SambaPOS HELPER xml.Parse in your link.

var test= xml.getElementsByTagName(“tag”)[0];

like this you can use dynamic object i think.

I tried that already, I think it’s reading the file that gives me trouble

The line is incorrect:

var f = file.ReadFromFile('fileName');

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.

Thanks for your answer, I saw it already but do not solve my problem but thanks!

Almost there
File is loaded, it is a xml file.

it stops at xml.Parse (does not show the dlg.ShowMessage but that error.

imagen

Once I have the object

o

How do I get the DigestValue ?

Trying getElement gives:

imagen

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…

I could be wrong.

1 Like

SFS = program that takes input and sends output (xml) to the tax administration. That program is provided as it is by tax administration.

SambaPOS sends 3 text files to SFS

–> SFS build XML, hashes it, signs it and sends it to Tax Administration

–> Tax administration replies to SFS with XML (accepted/rejected), SFS stores that XML reply in a directory.

–> I would like that SambaPOS reads that XML in that directory and extracts 2 values from it to update 2 Ticket tags.

So which simple actions and rules would you suggest to handle it?

You got that error because o is not a string. change to dlg.ShowMessage(o.toString());

1 Like

imagen

The o object does not accept a lot of methods (nor toSting, nor Get Element, …) … problem is I have no clue on which methods it would accept.

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:

s.nodeValue
s[0].nodeValue
s[0].childNodes[0].nodeValue

I am just guessing as it is pretty impossible to do without testing a script myself.

Also have a look here, this is where I got the ideas for above:

1 Like

I tried it but getElement is also no accepted method:

imagen

That works I get the object o, but don’t know to get the value.

imagen

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.

Ok so I was wrong. That is why it’s important to explain what your doing so we see the bigger picture and give you better answers.