XML Question with NodeValue Property
jordi79
Member Posts: 281
Hi,
I have a question on XML. I have the follwing XML file...
And the following code:
The problem is when this code is executed it messages:
Microsoft Dynamics NAV
NewNodeValue1
NewSubNodeValue1
OK
What if I only want the text value for the current node, and not the current node and all it's child nodes?
I read somewhere that I am to use the property "NodeValue" for this, but I tried and it does not work. When I use print the results of NodeValue it only shows a symbol which looks like an 'r'. (I have attached a screenshot of this)
I have also lookedup the property NodeValue, and came across this code in http://www.devguru.com/technologies/xml ... Value.html
What I do not understand of this code is why did the FirstChild printed out the result "Eric"? When I would expect it to be "Alice", and for Last Child is suppose to be "Eric".
I have a question on XML. I have the follwing XML file...
<NodeName xmlns="MyNameSpace" ID="10000"> NodeValue <NewNode xmlns=""> NewNodeValue1 <NewSubNode> NewSubNodeValue1 </NewSubNode> </NewNode> <NewNode xmlns=""> NewNodeValue2 </NewNode> <NewNode xmlns=""> NewNodeValue3 </NewNode> </NodeName>
And the following code:
IF ISCLEAR(XMLDOMDocument) THEN
CREATE(XMLDOMDocument);
XMLDOMDocument.load('c:\MyXML.xml');
XMLDOMMgmt.SetNormalCase();
CurrNode := XMLDOMDocument.documentElement;
//-------------------------------------
// message a single node...
IF XMLDOMMgmt.FindNode(CurrNode, 'NewNode', CurrNode2) THEN BEGIN
MESSAGE(FORMAT(CurrNode2.text));
// *** this is the code to print from NodeValue
//EVALUATE(TempStr, CurrNode2.NodeValue);
//MESSAGE(TempStr);
END
ELSE
MESSAGE('Node not found!');
The problem is when this code is executed it messages:
Microsoft Dynamics NAV
NewNodeValue1
NewSubNodeValue1
OK
What if I only want the text value for the current node, and not the current node and all it's child nodes?
I read somewhere that I am to use the property "NodeValue" for this, but I tried and it does not work. When I use print the results of NodeValue it only shows a symbol which looks like an 'r'. (I have attached a screenshot of this)
I have also lookedup the property NodeValue, and came across this code in http://www.devguru.com/technologies/xml ... Value.html
XML: <names> <name>Alice</name> <name>Bert</name> <name>Charlie</name> <name>Diane</name> <name>Eric</name> </names>
Code (VBScript):
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("names.xml")
Set objNode = objXMLDoc.documentElement.lastChild
document.write(objNode.nodeValue)
Set objNode = objNode.firstChild
document.write("<br>" & objNode.nodeValue)
Output:
null
Eric
What I do not understand of this code is why did the FirstChild printed out the result "Eric"? When I would expect it to be "Alice", and for Last Child is suppose to be "Eric".
0
Comments
-
I would consider using the XML Node's Text property. This should display the clear text value of the data inside the node.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K 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
- 324 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