XSD Schema for special characters - Excel import

假如想象 提交于 2019-12-24 21:27:15

问题


I'm fairly new to XML and it's not a regular part of my day job. However, I've been attempting to export a large database and import into Microsoft Excel for data processing purposes.

Where I've gotten stuck is that special character coding is not being recognised by Excel. My XML export contains data such as:

– & û Æ

Among others. The error I get is "Reference to undefined entity ndash", etc.

On export the file created a DTD file w/these definitions, but on searching google somewhere mentioned that Excel doesn't support DTD (I was getting an error so I presumed so). So I've tried writing an XSD which defines these items. Which looks something like this:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://www.w3schools.com"
xmlns="https://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="&ucirc;">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:pattern value="u"/>
    </xs:restriction>
    </xs:simpleType>
</xs:element>
<xs:element name="&ndash;">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:pattern value="n"/>
    </xs:restriction>
    </xs:simpleType>
</xs:element>
</xs:schema>

But with no luck on import. Anyone have suggests to help a newb?

Bump?

EDIT: I was able to get over this issue, by cheating and simply replacing the HTML codes with Unicode

So:

&ndash;

Became:

&#x2013;

I'd still be interested in figuring out how I could more easily write this up in an XSD schema so all the HTML instances are automatically replaced by Unicode ones? I thought something as simple as:

<xsd:attribute name="ndash" fixed="&#x2013;"/>

Would work but nope!


回答1:


You can declare entities inline in your XML files. Check it out here: DTD Entities vs XML-Schema Elements

Another useful link: https://en.wikipedia.org/wiki/Module:Unicode_chart/entities



来源:https://stackoverflow.com/questions/58060392/xsd-schema-for-special-characters-excel-import

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!