Formatting a numeric for an XML

AitorEGAitorEG Member Posts: 342
Hi everyone,

I am creating an XML file for deploy it into an external application. In the NAV record, I have a decimal value (Gross Weight (Kg), that I must write it on a node in that XML file.
I am using this for adding to the node:

lvl5XMlNode := XMLDocOut.createNode(1,'TOTALWEIGHT','');
lvl4XMlNode.appendChild(lvl5XMlNode);
PackingHeader.CALCFIELDS("Gross Weight (Kg)");
DomTextNode := XMLDocOut.createTextNode(FORMAT(PackingHeader."Gross Weight (Kg)"));
lvl5XMlNode.appendChild(DomTextNode);

I am formating to a text tyope, because the node as to be a text, but when processing the XML file in the external application, I see this error:
TOTALWEIGHT specified must be numeric

How can I use the format expression to generate a numeric node?

Thank you very much!




Best Answer

Answers

  • AitorEGAitorEG Member Posts: 342
    Solved using:
    lvl5XMlNode := XMLDocOut.createNode(1,'TOTALWEIGHT','');
    lvl4XMlNode.appendChild(lvl5XMlNode);
    PackingHeader.CALCFIELDS("Gross Weight (Kg)");
    [b]Num2String :=FORMAT(PackingHeader."Gross Weight (Kg)");
    Num2String := SELECTSTR(1,Num2String) + '.' + SELECTSTR(2,Num2String);[/b]
    DomTextNode := XMLDocOut.createTextNode(Num2String);
    lvl5XMlNode.appendChild(DomTextNode);
    
  • YuryYury Member Posts: 59
    Be careful, it depends on your regional settings delimiter
    Regards,
    Yury
  • AitorEGAitorEG Member Posts: 342
    Yury wrote: »
    Be careful, it depends on your regional settings delimiter

    Thank you, I'll take care of it.
  • AitorEGAitorEG Member Posts: 342
    NavNab wrote: »
    Hello @AitorEG

    All you need is:
    FORMAT(MyValue, 0, '<Standard Format,9>');
    

    Thanks, It worked perfectly, and it's simpler than my solution.
    Really thanks!
  • NavNabNavNab Member Posts: 181
    You're welcome. I'm glad it helps :)
  • JuhlJuhl Member Posts: 724
    You can even write it like 0,9)
    Follow me on my blog juhl.blog
Sign In or Register to comment.