【问题标题】:parsing DataTable XML output, junk after document element error解析 DataTable XML 输出,文档元素错误后出现垃圾
【发布时间】:2015-01-29 17:45:29
【问题描述】:

我正在尝试获取数据库记录并在 XML 标记中打印它们。

使用DataTable类,输出是这样的:

<xs:schema
    xmlns=""
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
    <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="c" msdata:UseCurrentLocale="true">
        <xs:complexType>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element name="c">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="ID" type="xs:int" minOccurs="0"/>
                            <xs:element name="TYPE" type="xs:int" minOccurs="0"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:choice>
        </xs:complexType>
    </xs:element>
</xs:schema>
<diffgr:diffgram
    xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
    xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
    <DocumentElement
        xmlns="">
        <c diffgr:id="c1" msdata:rowOrder="0">
            <ID>12224</ID>
            <TYPE>2</TYPE>
        </c>
        <c diffgr:id="c2" msdata:rowOrder="1">
            <ID>12225</ID>
            <TYPE>2</TYPE>
        </c>
        <c diffgr:id="c3" msdata:rowOrder="2">
            <ID>12298</ID>
            <TYPE>1</TYPE>
        </c>
        <c diffgr:id="c4" msdata:rowOrder="3">
            <ID>12299</ID>
            <TYPE>1</TYPE>
        </c>
        <c diffgr:id="c5" msdata:rowOrder="4">
            <ID>12300</ID>
            <TYPE>1</TYPE>
        </c>
        <c diffgr:id="c6" msdata:rowOrder="5">
            <ID>12301</ID>
            <TYPE>1</TYPE>
        </c>
    </DocumentElement>
</diffgr:diffgram>

似乎有效,但是当我试图在另一个 PHP 脚本中解析它时,它会抛出一个错误:

XML Parsing Error: junk after document element Line Number 20, Column 1

有什么问题? codebeutify 现场演示:http://codebeautify.org/xmlviewer/848b20

【问题讨论】:

    标签: xml vb.net datatable


    【解决方案1】:

    每个 XML 文件可能只包含一个根元素。你的有两个:xs:schemadiffgr:diffgram。您应该将架构放到单独的 xsd 文件中,并在需要时引用它。

    【讨论】:

      猜你喜欢
      • 2010-11-24
      • 2013-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多