获取某些标记的所有XML字段

时间:2014-12-01 01:19:59

标签: xml vb.net

如何从此XML获取列表中的所有字段?

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE doc_type_name SYSTEM  "R:\ftproot\graphics\ONIX_BookProduct_3.0_reference.dtd">
<ONIXMessage xmlns="http://www.editeur.org/onix/2.1/reference" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.editeur.org/onix/2.1/reference http://www.editeur.org/onix/2.1/ONIX_BookProduct_Release2.1_reference.xsd">
    <Header>
        <FromCompany>A company</FromCompany>
        <FromEmail>support@acompany.com</FromEmail>
        <SentDate>201408101343</SentDate>
        <MessageNote>Generated by a company</MessageNote>
        <DefaultLanguageOfText>eng</DefaultLanguageOfText>
    </Header>
    <Product>
        <WorkIdentifier>
            <WorkIDType>15</WorkIDType>
            <IDValue>9781861511126</IDValue>
        </WorkIdentifier>
    </Product>
    <Product>
        <RecordReference>9781861511690</RecordReference>
        <NotificationType>02</NotificationType>
        <RecordSourceType>01</RecordSourceType>
        <RecordSourceName>A company</RecordSourceName>
    </Product>
</ONIXMessage>

首先,我做到了这一点:

Dim xmlDoc As XDocument = New XDocument
    Dim products As List(Of XElement)

然后尝试以下各项无济于事,总是以空列表的形式返回:

products = xmlDoc.Element("ONIXMessage").Descendants("Product").ToList()
products = xmlDoc.Descendents("ONIXMessage").Descendants("Product").ToList()
products = xmlDoc.Descendants("Product").ToList()

我做错了什么?

0 个答案:

没有答案