Reading xml from variable

smshyd
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
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
0
Answers
-
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>0 -
Thanks for the reply , It was the problem with the XML , Now its working fine0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions