1

In the following example could you suggest what's the best way to read "ApplicationUrl" value using linq.

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
   <channel>
      <title>TestTitle</title>
      <item>
         <a10:content type="application/xml">
            <Vacancy xmlns="http://schemas.datacontract.org/2004/08/Har" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
               <AdvertText i:nil="true" />
               <ApplicationUrl>http://www.Test.co.uk/test/Sec/signin.aspx?vid=685</ApplicationUrl>
            </Vacancy>
         </a10:content>
      </item>
   </channel>
</rss>

I am trying to read using following linq query but stuck at content level

(from node in doc.Elements("channel").Elements("item")
 select new
 {
     Link = "link: " +node.Element("link").Value,
     Title = "Title: "+node.Element("title").Value,
     UpdatedOn ="Updated on : "+  node.Element(atom + "updated").Value,
     //here I have problem for getting Content properly
     Content = "Vacancy : " + XElement(node.Element(atom + "Vacancy"))
 })

1 Answer 1

1

You can try this way :

XNamespace ns = "http://schemas.datacontract.org/2004/08/Har";
XNamespace a10 = "http://www.w3.org/2005/Atom";
......
......
(from node in doc.Elements("channel").Elements("item")
 select new
 {
     Link = "link: " + (string)node.Element("link"),
     Title = "Title: "+ (string)node.Element("title"),
     UpdatedOn ="Updated on : "+ (string)node.Element(atom + "updated"),
     Content = "Vacancy : " + (string)node.Element(a10+"content")
                                          .Element(ns+"Vacancy")
                                          .Element(ns+"ApplicationUrl")
 })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.