如何适当地包含schemalocation以在xml中引用xsd文件

时间:2014-02-04 16:51:14

标签: c# xml xsd

我正在构建一个用于语音识别的xml语法文件,因此我创建了一个词典文件,并添加了lexicon元素,如下所示,架构位置给我错误

  1. 从文档中此位置引用的架构包含错误
  2. 操作已超时
  3. 粗体线导致错误

    xmlns="http://www.w3.org/2005/01/pronunciation-lexicon"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.w3.org/2005/01/pronunciation-lexicon
    **http://www.w3.org/TR/2007/CR-pronunciation-lexicon-20071212/pls.xsd"**
    alphabet="x-microsoft-ups" xml:lang="en-IN"
    

    我该怎么办?

1 个答案:

答案 0 :(得分:1)

您指向的架构有效。问题是,W3C网站上托管的模式有时会受到限制;在你的情况下更是如此,因为pls.xsd引用xml.xsd(这个肯定是受限制的)。

W3C限制对众所周知的XSD的响应,作为保护自己免受不必要流量的手段。

下载你的本地副本并参考这些副本,一切都应该没问题(假设其他一切都适合你)。

根据您的评论,这就是XML文件的样子:

<?xml version="1.0" encoding="utf-8"?> 
<lexicon version="1.0" 
    xmlns="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2005/01/pronunciation-lexicon file://C:/some/folder/where/your/xsd/file/is/pls.xsd" 
    alphabet="x-microsoft-ups" xml:lang="en-IN">
    <lexeme>

    </lexeme>
</lexicon>

pls.xsd顶部应该是这样的(在更改xml.xsd的模式位置之后,假设它们位于同一个文件夹中):

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Externals changed by QTAssistant (http://www.paschidev.com) -->

<!--
  This is a draft schema for the XML language defined in the 
  Pronunciation Lexicon Specification 
  (latest version at <http://www.w3.org/TR/pronunciation-lexicon/>)
  At the time of writing, the specification as well as this schema are
  subject to change, and no guarantee is made on their accuracy or the fact
  that they are in sync.
  Last modified: $Date: 2007/12/11 12:08:40 $

  Copyright &#251; 2006 World Wide Web Consortium, (Massachusetts Institute
  of Technology, ERCIM, Keio University). All Rights Reserved. See
        http://www.w3.org/Consortium/Legal/.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:p="http://www.w3.org/2005/01/pronunciation-lexicon" targetNamespace="http://www.w3.org/2005/01/pronunciation-lexicon" elementFormDefault="qualified" version="1.0">
    <xs:annotation>
        <xs:documentation>Importing dependent namespaces</xs:documentation>
    </xs:annotation>
    <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd" />

 ...
    </xs:schema>

在VS2010及以上版本都可以正常工作。