Reading xml from variable

smshydsmshyd Member Posts: 72
I am using nav 2009 R2 US version
I have taken one text variable containing xml data
Strng := '<ERPItemCode><Value>Itm1</Value></ERPItemCode>'+'<ERPItemVariantCode><Value>BLABLU</Value></ERPItemVariantCode> ' ;

I want to get ERPItemCode , So for that below code is used
IF ISCLEAR(xmldomDoc) THEN
CREATE(xmldomDoc);
xmldomDoc.loadXML(Xmltext);
strngg := 'ERPItemCode';
Strngvaraint := 'ERPItemVariantCode' ;
xmlNodeList1 := xmldomDoc.getElementsByTagName(strngg);
ii:=xmlNodeList1.length();
//MESSAGE('%1',xmlNodeList1.length());
FOR i:=0 TO xmlNodeList1.length()-1 DO BEGIN
xmldomElem1:= xmlNodeList1.item(i);
ItmNo[i+1] := xmldomElem1.text();
END;
MESSAGE('%1',ItmNo[i+1]);
Problem is that it is working fine when

Strng := '<ERPItemCode><Value>Itm1</Value></ERPItemCode>' ;

but it is not working if

Strng := '<ERPItemCode><Value>Itm1</Value></ERPItemCode>'+'<ERPItemVariantCode><Value>BLABLU</Value></ERPItemVariantCode> ' ;

i.e when something is prepend or appended to that variable

Answers

  • jensthomsenjensthomsen Member Posts: 173
    Hi smshyd

    The xml originating from the string:

    Strng := '<ERPItemCode><Value>Itm1</Value></ERPItemCode>'+'<ERPItemVariantCode><Value>BLABLU</Value></ERPItemVariantCode> ' ;

    is not valid. The first one is valid:

    <ERPItemCode><Value>Itm1</Value></ERPItemCode>

    A simple validation of a XML is to paste the content into a notepad, and save the file with .xml-extension. If you can run and view the content properly in an Explorer, the XML should be valid.

    Instead of
    <ERPItemCode><Value>Itm1</Value></ERPItemCode><ERPItemVariantCode><Value>BLABLU</Value></ERPItemVariantCode>
    a valid XML could look like this:
    <ERPItemCode><Value>Itm1</Value><ERPItemVariantCode><Value>BLABLU</Value></ERPItemVariantCode></ERPItemCode>
  • smshydsmshyd Member Posts: 72
    Thanks for the reply , It was the problem with the XML , Now its working fine
Sign In or Register to comment.