I’m trying to get values from AppServer, DbServer and AuthServer. My code is this:
dim xml as new XmlDocument
Dim nodesBody As XmlNodeList
Dim nodeSoapBody as xmlNode
if nodesBody>0 then nodeSoapBody= nodesBody.Item(0)
Here I get the soap:Body as a node. What I’m not been able to get is the values inside . I’ve tryed with all this variants with no luck:
dim nodes as XmlNodeList
dim node as xmlNode
nodes=nodeSoapBody.XQL("//FEDummyResponse") //1º try
nodes=nodeSoapBody.XQL("//FEDummyResult") //2º try
nodes=nodeSoapBody.XQL("//AppServer") //3º try
nodes=nodeSoapBody.XQL("FEDummyResponse") //4º try
I see using XQL inside a Node is not the same as using in a xml file. Am I right?
If I use:
I get the AppServer Node but nodeSoapBody.FirstChild.FirstChild.FirstChild.Name don’t get the value “Ok”.
Could somebody help me with this newee question?
And other related questions: What’s the difference in using xml.XQL("//variable") instead of xml.XQL(“variable”)?
The issue seems to be how XML namespaces are dealt with
And I have to admit I’m not sure how to deal with this using XQL
with the following code
Dim xml As New XmlDocument
Dim nodesBody As XmlNodeList
Dim nodeSoapBody As xmlNode
If nodesBody.Length > 0 Then
For i As Integer = 0 To nodesBody.Length - 1
Dim node As XmlNode = nodesBody.Item(i)
and a constant holding you original soap reply nothing is printed
IF I alter that reply to omit the xmlns attribute in DummyResponse so its like
The problem is the unqualified name space in your node (xmlns=“http://website.com/”)
this lead XQL to don’t understand the tree. (it’s a bug)
If you remove the xmlns=“http://website.com/” everything works correctly
To use NS in XQL you have to add an array as second parameter, this array must be created as a sequence of namesSpace name and nameSpace URL. IE array(“soap”, “http://schemas.xmlsoap.org/soap/envelope/”) and so on.
Sometimes an array like ("", “”) can solve this kind of problems, but in your case neither ("", “”) nor ("", “http://website.com/”) seems to work.
If you remove xmlns=“http://website.com/” your code will work (using DummyResponse and not FEDummyResponse)
Norman, I’ve tryed this and yes, it works and it confirm the problem is that line but I can’t code to specific remove this text because it could change with time.
Jeff, I’ve done this before with other XML files and it’s usefull. I could even just look for the value between “< AppServer >” and “< /AppServer >” with INSTR because in this case it will always be just one entry of this type but I wanted to learn the use of XML class. Maybe it’s not possibly with this XML and your solution is the most practical.
Antonio, I see, this is what I don’t entirely understand, the use of the map() array parameter. Could you explain it to me a little? What I’ve understand is that (in this case) I should use it like:
dim map() as String=array("xsd","http://www.w3.org/2001/XMLSchema","xsi","http://www.w3.org/2001/XMLSchema-instance","soap","http://schemas.xmlsoap.org/soap/envelope/")
What I don’t understand is when do I have to use it. In every XQL when a xml have namespaces on it whatever the tag is what I’m looking for? Why “nodes=xmlToParse.DocumentElement.XQL(“soap:Body”)” find the soap:Body tag without using the map()? I don’t have clear if I need to use for the entire xml o just to look inside a tag with namespaces on it.
A name space should be like var1:“http://website.com”
even if you never use the var1 name space (like in your case)
name spaces (obviously) are usefull to avoid colliding names from different sources (a document could be created by several tools and rules)
It is advisable to use the map array parameter if your xml has namespaces.
So you can remove the “local” namespace or declare it as var1…
A little tip: to read the AppServer value (and the others) instead of verify if the node exists and then if the text node exists and then take the value, you can search directly something like “AppServer/text()”
If the text node exists (xql lenght>0) then you have already the node and you can read its value.