I have a basic XML question.
Let's say that I have an XML document where the root element text / node
text is "<MyNamespace:MyXml>MyData</MyNamespace:MyXml>".
Therefore, let's say that the following:
Set xmlRootElement = xmlDoc.documentElement
Debug.Print xmlRootElement.Text
and, therefore, xmlRootElement.Text =
"<MyNamespace:MyXml>MyData</MyNamespace:MyXml>"
and, by same token, the following:
For Each xmlNode In xmlDoc.childNodes
Debug.Print xmlNode.Text
Next xmlNode
and, therefore, xmlNode.Text =
"<MyNamespace:MyXml>MyData</MyNamespace:MyXml>"
Considering the above, I want to know how to extract just the value embedded
in that text (i.e. "MyData"). Do I have to use traditional string parsing
or is there a way using the XML libraries to quickly say SomeObject.Value or
SomeObject.Text and Voila! I get the "MyData" value?
Thanks,
TC
var _oDom = null
function getSyncDom()
{
if (!_oDom)
{
_oDom = new ActiveXObject("Msxml2.DomDocument.6.0");
_oDom.async = false;
}
return _oDom.cloneNode(false);
}
function showParseError(error)
{
var sMessage = "Error loading document:\n\tReason: " + error.reason;
sMessage += "\n\tSource: " + error.srcText;
sMessage += "\n\tLine: " + error.line;
WScript.echo(sMessage);
}
function main()
{
var oDoc = getSyncDom();
var bLoaded = oDoc.loadXML('<MyNamespace:MyXml
xmlns:MyNamespace="http://myDomain.com/namespaceString">MyData</MyNamespace:MyXml>');
if (bLoaded)
{
WScript.echo(oDoc.documentElement.text);
}
else
{
showParseError(oDoc.parseError);
}
}
main();
--
Joe Fawcett (MVP - XML)
http://joe.fawcett.name
I think you've miss understood the .Text property. It simply concatenates
the values of all the text nodes inside the element and returns the result
(or the value of the node if its an Attribute).
Hence xmlRootElement.Text is "MyData".
--
Anthony Jones - MVP ASP/ASP.NET