0

I cannot figure out how to get the second link element in the item element. The one with the xmlns="csx" attribute.

I tried to specify the namespace but it did not work.

XNamespace linkNamespace = XNamespace.Get("http://schemas.microsoft.com/rss/2007/contentsyncextensions");  

var item = tree.Descendant("item");
item.Element(linkNamespace + "link");

xml is:

<rss version="2.0" xmlns:nd="http://schemas.newspaperdirect.com" xmlns:rx="http://schemas.microsoft.com/rss/2007/readerextensions" xmlns:csx="http://schemas.microsoft.com/rss/2007/contentsyncextensions">
    <channel>
        <title>The same is true for eurozone countries, assuming that the European Central Bank acts as the lender of last resort.</title>
        <link>http://library.pressdisplay.com/pressdisplay/viewer.aspx</link>
        <description>Search for : "The same is true for eurozone countries, assuming that the European Central Bank acts as the lender of last resort." (provided by PressDisplay.com)</description>
        <pubDate>Mon, 20 Dec 2021 00:00:00 GMT</pubDate>
        <lastBuildDate>Mon, 20 Dec 2021 01:21:44 GMT</lastBuildDate>
        <category>Total=9</category>
        <item rx:type="Story">
            <properties>
                <property key="newspaperTitle">Pakistan Today (Lahore)</property>
                <property key="newspaperCountry">Pakistan</property>
                <property key="newspaperLanguage">English</property>
            </properties>
            <page>8</page>
            <title>TIME TO OVERHAUL THE GLOBAL FINANCIAL SYSTEM</title>
            <link>http://library.pressdisplay.com/pressdisplay/pageview.aspx?issue=88502021120900000000001001&amp;page=8&amp;articleid=3077693453&amp;previewmode=2</link>
            <regionId>3077693453</regionId>
            <author>JEFFREY D SACHS Jeffrey D. Sachs, a professor at Columbia University, is director of the Center for Sustainable Development at Columbia University and president of the U.N. Sustainable Development Solutions Network.</author>
            <description>&lt;br/&gt;&lt;img alt="" title="" src="https://i.prcdn.co/img?regionguid=32ed40cc-778d-43ef-9b20-3a78bc7fe73d&amp;scale=67&amp;file=88502021120900000000001001&amp;regionKey=VIFA7LohZIEEFfwEXTBRgQ%3d%3d" width="80" style="float:left; margin-right:20px"/&gt; AT last month’s COP26 climate summit, hundreds of financial institutions declared that they would put trillions of dollars to work to finance solutions to climate change. Yet a major barrier stands in the way: The world’s financial system actually...</description>
            <pubDate>Thu, 09 Dec 2021 00:00:00 GMT</pubDate>
            <lastBuildDate xmlns="csx">Thu, 09 Dec 2021 00:00:00 GMT</lastBuildDate>
            <link xmlns="csx">http://library.pressdisplay.com/pressdisplay/services/rssarticleinfo.ashx?issue=88502021120900000000001001&amp;page=8&amp;articleid=3077693453</link>
            <pageimg xmlns="csx">https://i.prcdn.co/img?regionguid=32ed40cc-778d-43ef-9b20-3a78bc7fe73d&amp;scale=67&amp;file=88502021120900000000001001&amp;regionKey=VIFA7LohZIEEFfwEXTBRgQ%3d%3d</pageimg>
            <imageReferences xmlns="rx">
                <imageReference>
                    <caption>TIME TO OVERHAUL THE GLOBAL FINANCIAL SYSTEM</caption>
                    <credit>JEFFREY D SACHS Jeffrey D. Sachs, a professor at Columbia University, is director of the Center for Sustainable Development at Columbia University and president of the U.N. Sustainable Development Solutions Network.</credit>
                    <image height="120" width="80">
                        <link xmlns="csx">https://i.prcdn.co/img?regionguid=32ed40cc-778d-43ef-9b20-3a78bc7fe73d&amp;amp;scale=67&amp;amp;file=88502021120900000000001001&amp;amp;regionKey=VIFA7LohZIEEFfwEXTBRgQ%3d%3d</link>
                    </image>
                </imageReference>
            </imageReferences>
        </item>
    </channel>
</rss>

1 Answer 1

1

I suppose the XML is not correct:

<link xmlns="csx"> is an element name "link" in the namespace "csx", not in the namespace "http://schemas.microsoft.com/rss/2007/contentsyncextensions".

<csx:link> would be correct, if the namespace "http://schemas.microsoft.com/rss/2007/contentsyncextensions" is meant.

If really <link xmlns="csx"> is meant, use XNamespace linkNamespace = XNamespace.Get("csx")

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.