我无法使用textreader和dataset对象合并两个xml文档

时间:2013-06-03 21:15:26

标签: xml vb.net

我不确定我做错了什么,这是错误:'column' argument cannot be null. Parameter name: column

我想附加这个XML文档:

<?xml version="1.0" encoding="UTF-8"?>
<products>
    <product>
        <Name><![CDATA[G5]]></Name>
        <Type><![CDATA[44214]]></Type>
    </product>
    <product>
        <Name><![CDATA[G8]]></Name>
        <Type><![CDATA[44]]></Type>
    </product>
</products>

到这一个:

<?xml version="1.0" encoding="UTF-8"?>
<products>
    <product>
        <Name><![CDATA[G5]]></Name>
        <Brand><![CDATA[Sim]]></Brand>
        <Price><![CDATA[14]]></Price>
        <Price><![CDATA[8]]></Price>
    </product>
    <product>
        <Name><![CDATA[G8]]></Name>
        <Brand><![CDATA[Sim32]]></Brand>
        <Price><![CDATA[143]]></Price>
        <Price><![CDATA[84]]></Price>
    </product>
</products>

我的最终XML看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<products>
    <product>
        <Name><![CDATA[G5]]></Name>
        <Brand><![CDATA[Sim]]></Brand>
        <Price><![CDATA[14]]></Price>
        <Price><![CDATA[8]]></Price>
        <Type><![CDATA[44214]]></Type>
    </product>
    <product>
        <Name><![CDATA[G8]]></Name>
        <Brand><![CDATA[Sim32]]></Brand>
        <Price><![CDATA[143]]></Price>
        <Price><![CDATA[84]]></Price>
        <Type><![CDATA[44]]></Type>
    </product>
</products>

以下是我正在使用的代码:

    Dim objTextReaderOriginal As XmlTextReader = New XmlTextReader("original.xml")
    Dim objTextReaderToAppend As XmlTextReader = New XmlTextReader("to_append.xml")

    Dim dsOriginal As DataSet = New DataSet()
    Dim dsToAppend As DataSet = New DataSet()

    dsOriginal.ReadXml(objTextReaderOriginal)
    dsToAppend.ReadXml(objTextReaderToAppend)

    dsOriginal.Merge(dsToAppend)

    dsOriginal.WriteXml("complete.xml")

此行发生错误:dsOriginal.Merge(dsToAppend)

0 个答案:

没有答案