>source

항목 요소에서 두 번째 링크 요소를 가져오는 방법을 알 수 없습니다. xmlns="csx" 속성을 가진 것.

네임스페이스를 지정하려고 했지만 작동하지 않았습니다.

XNamespace linkNamespace= XNamespace.Get("http://schemas.microsoft.com/rss/2007/contentsyncextensions");
var item= tree.Descendant("item");
item.Element(linkNamespace + "link");

xml은 다음과 같습니다.

<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;
amp;page=8&amp;
amp;articleid=3077693453&amp;
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>&amp;
lt;br/&amp;
gt;&amp;
lt;img alt="" title="" src="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" width="80" style="float:left; margin-right:20px"/&amp;
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;
amp;page=8&amp;
amp;articleid=3077693453</link>            <pageimg 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</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;amp;scale=67&amp;
amp;amp;file=88502021120900000000001001&amp;
amp;amp;regionKey=VIFA7LohZIEEFfwEXTBRgQ%3d%3d</link>                    </image>                </imageReference>            </imageReferences>        </item>    </channel></rss>

  • 답변 # 1

    XML이 올바르지 않다고 가정합니다.

    <링크 xmlns="csx"> "http://schemas.microsoft.com/rss/2007/contentsyncextensions" 네임스페이스가 아니라 "csx" 네임스페이스의 "link" 이름입니다.

    <csx:링크> 네임스페이스 "http://schemas.microsoft.com/rss/2007/contentsyncextensions"를 의미하는 경우 정확합니다.

    만약 정말< 링크 xmlns="csx"> 의미하다, 사용하다XNamespace linkNamespace= XNamespace.Get("csx")

  • 이전 Python에서 헤더가 있는 데이터 프레임의 요약 출력을 변환하는 방법은 무엇입니까?
  • 다음 excel : 값이 날짜를 따르도록 vlookup 또는 매크로를 설정하는 방법