getElementsByTagName
PauliusPocius
Member Posts: 3
Hello guys,
I need to select value from xmlfile.
Variables:
XMLDOC@1003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A05-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.DOMDocument60";
DOCNode@1005 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 3.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v3.0'.IXMLDOMNode";
DOCNodeList@1006 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 3.0:{2933BF82-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v3.0'.IXMLDOMNodeList";
sessionid@1007 : Text;
Code:
DOCNodeList:=XMLDOC.getElementsByTagName('Data');
DOCNode :=DOCNodeList.item(0);
sessionid := DOCNode.selectNodes('SessionId').item(0).text;
MESSAGE(sessionid);
XML file looks like
<Data xsi:type="LoginInfoDto">
<SessionId>fQVic1y4Y7tetqTojdygAydPdZ2519s5zFryZFG5</SessionId>
</Data>
If I remove xsi:type="LoginInfoDto" from data element it's works fine, how can I do in my code that automaticly remove that line?
I need to select value from xmlfile.
Variables:
XMLDOC@1003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A05-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.DOMDocument60";
DOCNode@1005 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 3.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v3.0'.IXMLDOMNode";
DOCNodeList@1006 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 3.0:{2933BF82-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v3.0'.IXMLDOMNodeList";
sessionid@1007 : Text;
Code:
DOCNodeList:=XMLDOC.getElementsByTagName('Data');
DOCNode :=DOCNodeList.item(0);
sessionid := DOCNode.selectNodes('SessionId').item(0).text;
MESSAGE(sessionid);
XML file looks like
<Data xsi:type="LoginInfoDto">
<SessionId>fQVic1y4Y7tetqTojdygAydPdZ2519s5zFryZFG5</SessionId>
</Data>
If I remove xsi:type="LoginInfoDto" from data element it's works fine, how can I do in my code that automaticly remove that line?
0
Answers
-
I think this is your Solution:
NodeName := 'SessionId'
Function: GetNodeValueOfXMLParameters(XMLText : Text;NodeName : Text) : Text
IF XMLText = '' THEN
EXIT('');
XMLDoc := XMLDoc.XmlDocument;
XMLDoc.LoadXml(XMLText);
XMLNode := XMLDoc.SelectSingleNode(NodeName));
IF ISNULL(XMLNode) THEN
ERROR(NodeNotFound);
IF STRLEN(XMLNode.InnerText) > 0 THEN
EXIT(XMLNode.InnerText);
Name DataType Subtype Length
XMLDOMMgt Codeunit XML DOM Management
XMLDoc DotNet System.Xml.XmlDocument.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
XMLNode DotNet System.Xml.XmlNode.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
RootNode DotNet System.Xml.XmlNode.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'0 -
This will solve your case, Try this once please.
https://rockwithnav.wordpress.com/2016/12/30/remove-attribute-soap-request-xmlxmlport/Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0 -
Not really understand this article, my xml file looks like this:
<?xml version="1.0" encoding="utf-16"?>
<AnswerObject xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Data xsi:type="LoginInfoDto">
<SessionId>4a0kKV8NB0b37uwwozdFGOOPpJTAv1m8ZmSTsJBr</SessionId>
<State>0</State>
<StateDetails />
<RoleId>114</RoleId>
<ClientId>1130</ClientId>
<DealerId>5</DealerId>
<DealerGroupId>6</DealerGroupId>
<MainClientId>1130</MainClientId>
<PermissionTokens>
<string>CANCALCULATEDISTANCE</string>
<string>CARVIEW</string>
<string>CATEGORYVIEW</string>
<string>CONNECT_WEB</string>
<string>DOCUMENT_READ</string>
<string>DOCUMENT_SEND</string>
<string>FAVORITEMODIFY</string>
<string>FAVORITEVIEW</string>
<string>FIXBUG</string>
<string>GENERATE_REPORTS</string>
<string>GETTELEMETRY</string>
<string>MAP_READ</string>
<string>MAP_WRITE</string>
<string>MSG_READ</string>
<string>MSG_SEND</string>
<string>MULTI_USER</string>
<string>REPORT_MENU_VIEW</string>
<string>USERVIEW</string>
<string>DRIVINGREPORTVIEW</string>
<string>DRIVINGSETVIEW</string>
<string>NOTWORKING_NOTIF</string>
</PermissionTokens>
<UserLanguage>lt</UserLanguage>
</Data>
<ErrorCode>OK</ErrorCode>
</AnswerObject>
i cannot even load Xml file with dotnet XMLdocument:=XMLdocument.XmlDocument because it's UFC-16.
How can i read <SessionId> from this xml file?
0 -
@PauliusPocius
There are couple of ways to this. Did you tried this way
XmlNodeList := locautXmlDoc.getElementsByTagName('SesionIDt');
XmlNode := locautXmlNodeList.item(0); //
Message('%1',XmlNode.Text);
Hopefully you can get the value.
P.S - I got your request over my Blog too, thank you so much for that, if you still unable then please send me your Xml.Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0 -
Thanks, this code helped me:
XMLNodeList:= locautXmlDoc.GetElementsByTagName('SessionId');
XMLNode:=XMLNodeList.Item(0);
MESSAGE('%1',XMLNode.InnerText);
But still have problem with XML file:
<encoding="utf-16">
when i'm trying to locautXmlDoc.load i get this error
How i can avoid this error?
0 -
Hey,
Did you tried using UTF 8 or you are bound to use this?
Try removing this encoding from the XML declaration. Replace
<?xml version="1.0" encoding="utf-16"?>
with
<?xml version="1.0"?>Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 329 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
