XLINQ to Query and Validate Parts?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • coconet

    XLINQ to Query and Validate Parts?

    I have a document that looks like the below. In the .NET 2.0 days, I
    might use an XmlDomDocument to read the whole thing to see if it is a
    basically good XML document. Then I might step through it with a
    reader of some kind.

    The entire XML document is now huge. Way too big to go into a DOM
    document for parsing.

    I was wondering if I could use LINQ for XML to query the "level_1"
    parts to put each of them into something I can test, like a new
    object.

    Thanks.







    <?xml version="1.0" encoding="UTF-8"?>
    <Feed>
    <level_1>
    <url>http://www.aaaaaa.com</url>
    <urlalt>http://www.aaaaa.net</urlalt>
    <title>title from one</title>
    <desc>descripti on from one</desc>
    <richdata>
    <![CDATA[
    this is rich data from one
    ]]>
    </richdata>
    <subdata>
    <subdata_a>
    <title>sub-a</title>
    <info>sub-a information</info>
    </subdata_a>
    </subdata>
    </level_1>
    <level_1>
    <url>http://www.bbbbb.com</url>
    <urlalt>http://www.bbbbb.net</urlalt>
    <title>title from two</title>
    <desc>descripti on from two</desc>
    <richdata>
    <![CDATA[
    this is rich data from two
    ]]>
    </richdata>
    <subdata>
    <subdata_a>
    <title>sub-b</title>
    <info>sub-b information</info>
    </subdata_a>
    </subdata>
    </level_1>
    </Feed>
  • Martin Honnen

    #2
    Re: XLINQ to Query and Validate Parts?

    coconet wrote:
    I was wondering if I could use LINQ for XML to query the "level_1"
    parts to put each of them into something I can test, like a new
    object.
    If I understand you correctly then the document contains other elements
    besides the "level_1" elements and you only want to store the level_1
    stuff. In that case have a look at the approach described in
    http://msdn.microsoft.com/en-us/library/bb387008.aspx, it shows how to
    use the ReadFrom method to read an XML fragment from an XmlReader.


    --

    Martin Honnen --- MVP XML

    Comment

    Working...