XML to List

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have the following xml that I am pulling from a service:<br/>
<br/>

<pre class="prettyprint" style="border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; font-size:13px; vertical-align:baseline; background-color:#f0f3f4; line-height:1.2em; min-height:35px; overflow-x:auto; overflow-y:auto; width:798px; font-family:Consolas,Courier New,Courier,monospace <span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <results><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <br/><span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="x_Apple-tab-span" style="white-space:pre <result><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <br/><span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="x_Apple-tab-span" style="white-space:pre <displayName><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent Joe Blow<span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent </displayName><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <br/><span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="x_Apple-tab-span" style="white-space:pre <department><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent Real Estate<span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent </department><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <br/><span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="x_Apple-tab-span" style="white-space:pre <ape><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <br/><span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="x_Apple-tab-span" style="white-space:pre <phone<span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="atn" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent type<span class="pun" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent =<span class="atv" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent "Mobile"<span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="atn" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent typeId<span class="pun" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent =<span class="atv" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent "6"<span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="atn" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent relationship<span class="pun" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent =<span class="atv" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent "Business"<span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="atn" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent relationshipId<span class="pun" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent =<span class="atv" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent "1"<span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent ><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <br/><span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="x_Apple-tab-span" style="white-space:pre <formattedPhone><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent (555) 555-5555<span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent </formattedPhone><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <br/><span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="x_Apple-tab-span" style="white-space:pre </phone><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <br/><span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="x_Apple-tab-span" style="white-space:pre </ape><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <br/><span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="x_Apple-tab-span" style="white-space:pre <additionalFields><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <br/><span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="x_Apple-tab-span" style="white-space:pre <additionalField><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <br/><span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="x_Apple-tab-span" style="white-space:pre <definitionId><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent 8589935558<span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent </definitionId><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <br/><span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="x_Apple-tab-span" style="white-space:pre <name><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent Floor Location<span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent </name><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <br/><span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="x_Apple-tab-span" style="white-space:pre <value><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent 2373<span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent </value><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <br/><span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="x_Apple-tab-span" style="white-space:pre <displayValue><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent 2373<span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent </displayValue><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <br/><span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="x_Apple-tab-span" style="white-space:pre </additionalField><span class="pln" style="margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span style="color:#222222 <br/><span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="x_Apple-tab-span" style="white-space:pre </additionalFields><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <br/><span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <span class="x_Apple-tab-span" style="white-space:pre </result><span class="pln" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent <br/><span class="tag" style="color:#222222; margin-bottom:0px; padding-bottom:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; vertical-align:baseline; background-color:transparent </results>[/code]
I am using the following code:<br/>

StreamReader reader = new StreamReader(data);<br/>
<br/>
XDocument xdoc = XDocument.Parse(reader.ReadToEnd());<br/>
<br/>
<span class="x_Apple-tab-span" style="white-space:pre var contact = from contacts in xdoc.Descendants("result")<br/>
<span class="x_Apple-tab-span" style="white-space:pre where contacts.Element("department") != null && contacts.Element("jobTitle") != null<br/>
<span class="x_Apple-tab-span" style="white-space:pre select new<br/>
<span class="x_Apple-tab-span" style="white-space:pre {<br/>
<span class="x_Apple-tab-span" style="white-space:pre displayname = contacts.Element("displayname").Value,<br/>
<span class="x_Apple-tab-span" style="white-space:pre department = contacts.Element("department").Value<br/>
<span class="x_Apple-tab-span" style="white-space:pre /*office = ?????*/<span class="x_Apple-tab-span" style="white-space:pre
<br/>
<span class="x_Apple-tab-span" style="white-space:pre }
<br/>

What I am trying to get is one list with<br/>
<br/>
displayname,<br/>
department,<br/>
office (which is stored here <additionalFields><additionalField><value>2373</value></additionalFields></additionalField><br/>
<br/>
How do I modify my select to get this data?<br/>
<br/>
What is the best approach for this?<br/>
<br/>
Thanks in advance.

View the full article
 
Back
Top