• <bdo id='O7kAC'></bdo><ul id='O7kAC'></ul>

    <small id='O7kAC'></small><noframes id='O7kAC'>

  1. <tfoot id='O7kAC'></tfoot>

    <i id='O7kAC'><tr id='O7kAC'><dt id='O7kAC'><q id='O7kAC'><span id='O7kAC'><b id='O7kAC'><form id='O7kAC'><ins id='O7kAC'></ins><ul id='O7kAC'></ul><sub id='O7kAC'></sub></form><legend id='O7kAC'></legend><bdo id='O7kAC'><pre id='O7kAC'><center id='O7kAC'></center></pre></bdo></b><th id='O7kAC'></th></span></q></dt></tr></i><div id='O7kAC'><tfoot id='O7kAC'></tfoot><dl id='O7kAC'><fieldset id='O7kAC'></fieldset></dl></div>
    <legend id='O7kAC'><style id='O7kAC'><dir id='O7kAC'><q id='O7kAC'></q></dir></style></legend>

      将 XSD 与包含一起使用

      时间:2023-06-02

      • <small id='7UjrV'></small><noframes id='7UjrV'>

        <i id='7UjrV'><tr id='7UjrV'><dt id='7UjrV'><q id='7UjrV'><span id='7UjrV'><b id='7UjrV'><form id='7UjrV'><ins id='7UjrV'></ins><ul id='7UjrV'></ul><sub id='7UjrV'></sub></form><legend id='7UjrV'></legend><bdo id='7UjrV'><pre id='7UjrV'><center id='7UjrV'></center></pre></bdo></b><th id='7UjrV'></th></span></q></dt></tr></i><div id='7UjrV'><tfoot id='7UjrV'></tfoot><dl id='7UjrV'><fieldset id='7UjrV'></fieldset></dl></div>

              <tbody id='7UjrV'></tbody>
            <tfoot id='7UjrV'></tfoot>
            <legend id='7UjrV'><style id='7UjrV'><dir id='7UjrV'><q id='7UjrV'></q></dir></style></legend>
                <bdo id='7UjrV'></bdo><ul id='7UjrV'></ul>
                本文介绍了将 XSD 与包含一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                这是一个 XSD:

                <?xml version="1.0"?>
                <xsd:schema 
                elementFormDefault='unqualified' 
                attributeFormDefault='unqualified' 
                xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
                >
                
                  <xsd:simpleType name='TheSimpleType'>
                    <xsd:restriction base='xsd:string' />
                  </xsd:simpleType>
                </xsd:schema>
                

                这是第二个 XSD,包括上面的一个:

                Here is a second XSD that includes the one above:

                <?xml version="1.0" encoding="UTF-8" ?>
                <xsd:schema 
                elementFormDefault='unqualified' 
                attributeFormDefault='unqualified' 
                xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
                targetNamespace='a'
                xmlns='a'
                >
                
                  <xsd:include schemaLocation='Include.xsd' />
                
                  <xsd:element name = "TheElement" >
                  <xsd:complexType>
                  <xsd:attribute name="Code" type="TheSimpleType" use="required"/>
                  </xsd:complexType>
                  </xsd:element>
                </xsd:schema>
                

                我需要将(第二个)XSD 读入 C# 并且:

                I need to read the (second) XSD into C# and:

                1. 检查它是否是有效的 XSD,并且
                2. 根据它验证文档.

                这里有一些 C# 可以在架构中阅读:

                Here is some C# to read in the schemata:

                    XmlSchemaSet schemaSet = new XmlSchemaSet();
                    foreach (string sd in Schemas)
                    {
                        using (XmlReader r = XmlReader.Create(new FileStream(sd, FileMode.Open)))
                        {
                            schemaSet.Add(XmlSchema.Read(r, null));
                        }
                    }
                    schemaSet.CompilationSettings = new XmlSchemaCompilationSettings();
                    schemaSet.Compile();
                

                .Compile() 失败,因为类型 'a:TheSimpleType' 未声明,或者不是简单类型."

                The .Compile() fails because "Type 'a:TheSimpleType' is not declared, or is not a simple type."

                但是,如果满足以下任一条件,它就会起作用:

                However, it works if either:

                • 命名空间已从架构中移除,或者
                • 命名空间被添加到包含中.

                问题是:如何在不编辑模式的情况下让 C# 接受它?

                The question is: how do I get C# to accept it without editing the schemata?

                我怀疑问题在于,虽然我已将两个模式都放入 XmlSchemaSet,但我仍然需要告诉 C# 一个包含在另一个中,即它自己并没有解决.事实上,如果我只告诉 XmlSchemaSet 主 XSD(而不是包含)(都没有(或有)命名空间),那么类型 'TheSimpleType' 没有声明,或者不是简单类型."

                I suspect the problem is that although I have put both schemata into the XmlSchemaSet, I still need to tell C# that one is included into the other, i.e., it hasn't worked it out for itself. Indeed, if I only tell the XmlSchemaSet about the main XSD (and not the include) (both without (or with) namespaces) then "Type 'TheSimpleType' is not declared, or is not a simple type."

                因此这似乎是一个关于解决的问题包括:如何?!

                Thus this seems to be a question about resolving includes: how?!

                推荐答案

                问题在于在线打开模式读取的方式:

                The problem is with the way the schema is opened for reading on the line:

                XmlReader.Create(new FileStream(sd, FileMode.Open)
                

                我必须编写自己的 XmlResolver 才能看到如何解析包含文件的路径:它来自可执行文件的目录,而不是来自父架构的目录.问题是父模式没有得到它的 BaseURI 集.以下是必须打开模式的方式:

                I had to write my own XmlResolver before I could see how the paths to the include files were being resolved: it was from the directory of the executable and not from the directory of the parent schema. The problem is that the parent schema was not getting its BaseURI set. Here's how the schema must be opened:

                XmlReader.Create(new FileStream(pathname, FileMode.Open, FileAccess.Read),null, pathname)
                

                这篇关于将 XSD 与包含一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:在 C# 中生成随机盐的最佳方法? 下一篇:使用 .NET 针对架构验证 XML

                相关文章

                最新文章

                  <i id='8bWCT'><tr id='8bWCT'><dt id='8bWCT'><q id='8bWCT'><span id='8bWCT'><b id='8bWCT'><form id='8bWCT'><ins id='8bWCT'></ins><ul id='8bWCT'></ul><sub id='8bWCT'></sub></form><legend id='8bWCT'></legend><bdo id='8bWCT'><pre id='8bWCT'><center id='8bWCT'></center></pre></bdo></b><th id='8bWCT'></th></span></q></dt></tr></i><div id='8bWCT'><tfoot id='8bWCT'></tfoot><dl id='8bWCT'><fieldset id='8bWCT'></fieldset></dl></div>

                  <tfoot id='8bWCT'></tfoot>
                1. <legend id='8bWCT'><style id='8bWCT'><dir id='8bWCT'><q id='8bWCT'></q></dir></style></legend>

                    <bdo id='8bWCT'></bdo><ul id='8bWCT'></ul>
                2. <small id='8bWCT'></small><noframes id='8bWCT'>