c# - Parse XML response and return collection of objects -
I have found several different examples of parsing an XML file and most of the time I get a share of the way But I can not find an example that works, I need it.
Looking at the following XML responses
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Soap: envelope xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: xsd = "http://www.w3.org/2001/XMLSchema" xmlns: soap = "http: //schemas.xmlsoap.org/soap/envelope/"> & Lt; Soaps: Body & gt; & Lt; Parentnode xmlns = "http://my.own.namespace.com/" & gt; & Lt; ChildNode & gt; & Lt; Value 1 and gt; The string & lt; Value 1 and gt; & Lt; Value2 & gt; The string & lt; Value2 & gt; & Lt; / ChildNode & gt; & Lt; ChildNode & gt; & Lt; Value 1 and gt; The string & lt; Value 1 and gt; & Lt; Value2 & gt; The string & lt; Value2 & gt; & Lt; / ChildNode & gt; & Lt; / ParentNode & gt; & Lt; / Soap: body & gt; & Lt; / Soap: Envelope & gt;
How do I return a collection of ChildNode objects that came with values from Value1 and Value2?
I have found a list of the most far away values 1 strings like
var soap = XDocument.Parse (feedback); XNamespace ns = XNamespace.Get ("http://my.own.namespace.com/"); Var objectList = Soap.Decendants (Ns + "Parentnode"); . Select (x = & gt; x.Elements (.first value) .Oolist ();
I also tried to use XSD tool but it gave an error which could not be found.
Thanks for any help, I'm sure this one is
Try this way:
XNamespace ns = XNamespace.Get ("http://my.own.namespace.com/"); Var objectList = Soap.Decendants (Ns + "Parentnode"); . Select (x = & gt; New ChildNode {value1 = (string) x.Element (ns + "Value1"), value 2 = (string) x.Element (ns + "Value2"),}). Catalog ();
I assume that you have ChildNode
class with two property type string
:
And value2
.
Comments
Post a Comment