XML Question with NodeValue Property

jordi79jordi79 Member Posts: 274
Hi,
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".

Comments

  • jlandeenjlandeen Member Posts: 524
    I would consider using the XML Node's Text property. This should display the clear text value of the data inside the node.
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
Sign In or Register to comment.