HomeGenie Forum
Automation Program Plugins and Wizard Scripting => Help => Topic started by: Jens on June 26, 2016, 08:48:39 PM
-
Hello,
I am doing a soap request with Net.WebService(...) and .Post("<?xml version=\"1.0\"....
string result = request.Call();
result contains the XML response, doing a
Program.Notify("Show Result", result);
the pop up shows up displaying the values which are part of the xml like
"param1 param2 param3 param4"
If I do a
string[] reqs = (result.Split(' '));
and display reqs [1] I get part of the xml code not param1.
How can I decode the xml?
Many thanks
Best regards
Jens
-
don't store the response as a string, store it as XML you can then use Xpath to get what you want, Have you got sample XML you can post?
-
so you can do something like this and then look at the msdn example and dependant on your xml :)
var doc = new System.Xml.XmlDocument();
doc.LoadXml(request.Call());
have a look at https://msdn.microsoft.com/en-us/library/d271ytdx(v=vs.110).aspx (https://msdn.microsoft.com/en-us/library/d271ytdx(v=vs.110).aspx)
-
Thanks a lot for helping, this is the xml reply
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:GetGenericHostEntryResponse xmlns:u="urn:dslforum-org:service:Hosts:1">
<NewIPAddress>192.168.0.1</NewIPAddress>
<NewAddressSource>DHCP</NewAddressSource>
<NewLeaseTimeRemaining>0</NewLeaseTimeRemaining>
<NewMACAddress>AA:BB:CC:DD:EE:FF</NewMACAddress>
<NewInterfaceType>Ethernet</NewInterfaceType>
<NewActive>0</NewActive>
<NewHostName>phone</NewHostName>
</u:GetGenericHostEntryResponse>
</s:Body>
</s:Envelope>
I wanna further process the data of <NewActive>
Again, many thanks
-
var theXmlString = request.Call();
// Create XML Document and load the XML
var doc = new System.Xml.XmlDocument();
doc.LoadXml(theXmlString);
// Create Namespace manager
var xmlnsManager = new System.Xml.XmlNamespaceManager(doc.NameTable);
xmlnsManager.AddNamespace("u", "urn:dslforum-org:service:Hosts:1");
var node = doc.SelectSingleNode("//NewActive", xmlnsManager);
var newActive = node.InnerText;
Console.WriteLine(newActive);
Try that, my testing within visual studio suggests it should work :)
-
Many thanks, this helped me a lot
Regards
Jens
-
Not the best code I've ever written as I hate XML with a passion, but if it works :)
-
Hi David
I did an upgrade to mono and I am running now
mono --version
Mono JIT compiler version 4.6.0 (Stable 4.6.0.245/746756c Wed Sep 21 15:11:18 UTC 2016)
the same code causes now the following compile error
The type or namespace name `Xml' does not exist in the namespace `System'. Are you missing `System.Xml' assembly reference?
Do you have any clue what I can do to make it work again?
Thanks
Best Regards
Jens
-
Try going into the program and re-compile it..
-
Did that and the error message pops up.
As I found no other solution I am meanwhile back on mono 4.2.2.