XML查询问题

发布于 2024-12-16 13:30:19 字数 1634 浏览 0 评论 0原文

我正在尝试从 C# 编码的 xml 文件中获取一些数据。

如果以下claim-ib-info节点不包含已撤回,如何获取claim节点的数据节点。

如果您不清楚我的问题,请告诉我。

我对 XML 不太了解,提前致谢。

<info>
    <claim kind="national" sequence="1">
        <country>UK</country>
        <number>66</number>
        <date>20080602</date>
    </claim>
    <claim-ib-info>
        <received-at>
            <date>20090610</date>
        </received-at>
    </claim-ib-info>


    <claim kind="national" sequence="2">
        <country>US</country>
        <number>125</number>
        <date>20080501</date>
    </claim>
    <claim-ib-info>
        <withdrawn>
            <date>20100721</date>
        </withdrawn>
    </claim-ib-info>


    <claim kind="national" sequence="3">
        <country>TH</country>
        <number>61</number>
        <date>20090316</date>
    </claim>
    <claim-ib-info>
        <received-at>
            <date>20090610</date>
        </received-at>
    </claim-ib-info>


    <claim kind="national" sequence="4">
        <country>MY</country>
        <number>66</number>
        <date>20090209</date>
    </claim>
    <claim-ib-info>
        <withdrawn>
            <date>20101221</date>
        </withdrawn>
    </claim-ib-info>
</info>

I am trying to get some data from xml file from my C# coding.

How can I get the data of claim node if the following claim-ib-info node does not contain withdrawn node.

If you are not clear about my question, let me know.

I don't know much about XML and thanks in advance.

<info>
    <claim kind="national" sequence="1">
        <country>UK</country>
        <number>66</number>
        <date>20080602</date>
    </claim>
    <claim-ib-info>
        <received-at>
            <date>20090610</date>
        </received-at>
    </claim-ib-info>


    <claim kind="national" sequence="2">
        <country>US</country>
        <number>125</number>
        <date>20080501</date>
    </claim>
    <claim-ib-info>
        <withdrawn>
            <date>20100721</date>
        </withdrawn>
    </claim-ib-info>


    <claim kind="national" sequence="3">
        <country>TH</country>
        <number>61</number>
        <date>20090316</date>
    </claim>
    <claim-ib-info>
        <received-at>
            <date>20090610</date>
        </received-at>
    </claim-ib-info>


    <claim kind="national" sequence="4">
        <country>MY</country>
        <number>66</number>
        <date>20090209</date>
    </claim>
    <claim-ib-info>
        <withdrawn>
            <date>20101221</date>
        </withdrawn>
    </claim-ib-info>
</info>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萤火眠眠 2024-12-23 13:30:19

尝试学习和使用Linq to XML。

var list = from ele in XDocument.Load(@"c:\files.xml").Descendants("claim-ib-info")
                    where ele.Element("withdrawn")!=null
                   select ele.PreviousNode  ;

foreach (var t in list)
{
    Console.WriteLine(t);
}

Try to learn and use Linq to XML.

var list = from ele in XDocument.Load(@"c:\files.xml").Descendants("claim-ib-info")
                    where ele.Element("withdrawn")!=null
                   select ele.PreviousNode  ;

foreach (var t in list)
{
    Console.WriteLine(t);
}
洛阳烟雨空心柳 2024-12-23 13:30:19

我建议首先学习 XPath。 XPath(与 LINQ 不同)是一种开放技术;您可以在任何平台上使用任何支持 XML 的语言和库:

http: //msdn.microsoft.com/en-us/library/d271ytdx.aspx

I'd recommend learning XPath first. XPath (unlike LINQ) is an open technology; you can use it on any platform, with any XML-aware language and library:

http://msdn.microsoft.com/en-us/library/d271ytdx.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文