【问题标题】:Parsing XML file from SQLServer从 SQLServer 解析 XML 文件
【发布时间】:2013-02-14 06:32:36
【问题描述】:

我收到了一个“xml”文件,但它看起来并不像 XML。我知道它是从 Microsoft Access 或 SQLServer 导出的。该文件如下所示:

>>> contents[:1000]
'\xef\xbb\xbf<?xml version="1.0"?><Report xmlns="Ascent_x0_Metadata_x0020_Report_x0020__x002ted" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="Ascent_x0020_Me0_Repo29__x0020_updated http://reportserver?
%2fAsata+Report+(by+Title+Letter)+updated&amp;rs%3aFormat=XML&amp;rc%3aSchema=True" 
Name="Ascent Report (by Title Letter) updated">
    <table1>
        <Detail_Collection>
            <Detail ISOCountry="AR" TitleSort="A Very Brady Sequel" 
                ReleaseYear="1996" TitleKind="N/A" TitleType="N/A"...

此外,我什至无法在TextMate 中打开这个文件——每次我尝试打开它都会使程序崩溃。

【问题讨论】:

  • \xef\xbb\xbf 是。我不知道这是否有帮助,但就是这样。在我看来,它确实像 XML。只是在前几个字节中有一些垃圾?

标签: python sql-server xml ms-access xml-parsing


【解决方案1】:

第一个十六进制字符是 UTF-8 字节顺序标记 (http://en.wikipedia.org/wiki/Byte_order_mark0xEF,0xBB,0xBF)。

这只是意味着您收到的内容被编码为 UTF-8,您应该通过设置用于读取它的编码来处理它。就 XML 而言,文件的其余部分看起来还不错。

Textmate 应该可以使用 UTF-8,但文件可能太大了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-27
    • 2014-02-18
    • 1970-01-01
    • 1970-01-01
    • 2011-11-20
    • 2014-08-23
    • 2019-06-13
    相关资源
    最近更新 更多