简体   繁体   English

从外部xml模式派生

[英]derive from foreign xml schema

This is an xml example I want to be able to validate with my selfmade schema. 这是一个XML示例,我希望能够使用我的自制模式进行验证。 The whole EncryptedData part is actually syntax of the XML Encryption specification. 整个EncryptedData部分实际上是XML Encryption规范的语法。

<?xml version="1.0" encoding="UTF-8"?>
<Foo xmlns="http://www.foo.org/FOO">
    <EncryptedData>
        <EncryptionMethod
            Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
        <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
            <ds:KeyName>John Smith</ds:KeyName>
        </ds:KeyInfo>
        <CipherData>
            <CipherValue>DEADBEEF</CipherValue>
        </CipherData>
    </EncryptedData>
</Foo>

So I tried deriving from XML Encryption and came up with this: 因此,我尝试从XML加密派生并提出了以下建议:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xenc='http://www.w3.org/2001/04/xmlenc#'
    xmlns:xenc11="http://www.w3.org/2009/xmlenc11#"
    xmlns:foo="http://www.foo.org/Foo"
    targetNamespace="http://www.foo.org/Foo">
    <xsd:import namespace='http://www.w3.org/2001/04/xmlenc#' />
    <xsd:import namespace='http://www.w3.org/2009/xmlenc11#' />
    <xsd:element name="Foo">
        <xsd:complexType>
            <xsd:choice>
                <xsd:element name="myItem" minOccurs="1" maxOccurs="unbounded" type="anyType"/>
                <xsd:element ref="xenc:EncryptedData" minOccurs="1"
                    maxOccurs="unbounded" />
            </xsd:choice>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

But then my actual xml would have to look like this. 但是然后我的实际xml必须看起来像这样。 I need to prefix all the XML Encryption elements with namespaces as I imported them. 导入它们时,需要在所有XML Encryption元素前面加上名称空间。

<?xml version="1.0" encoding="UTF-8"?>
<foo
    xmlns="http://www.foo.org/Foo"
    xmlns:xenc='http://www.w3.org/2001/04/xmlenc#'/>
    <xenc:EncryptedData>
        <xenc:EncryptionMethod
            Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
        <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
            <ds:KeyName>John Smith</ds:KeyName>
        </ds:KeyInfo>
        <xenc:CipherData>
            <xenc:CipherValue>DEADBEEF</xenc:CipherValue>
        </xenc:CipherData>
    </xenc:EncryptedData>
</foo>

But I also fail to actually change the import into an include as target namespaces differ. 但是由于目标名称空间不同,我实际上也无法将导入更改为包含。 (my own being different from the one defined in the xml encryption schema) Is there a way to do this so you can even use it without the namespaces? (我自己不同于xml加密模式中定义的方法)是否有一种方法可以使您甚至在没有名称空间的情况下使用它呢? Or will it only work with prefixes? 还是只能使用前缀?

You can change the default namespace in the root element 您可以在根元素中更改默认名称空间

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Liquid XML 2014 Developer Bundle Edition 12.1.2.5004 (http://www.liquid-technologies.com) -->
<fns:foo xmlns:fns="http://www.foo.org/Foo"
         xmlns='http://www.w3.org/2001/04/xmlenc#'>
    <EncryptedData>
        <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
        <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
            <ds:KeyName>John Smith</ds:KeyName>
        </ds:KeyInfo>
        <CipherData>
            <CipherValue>DEADBEEF</CipherValue>
        </CipherData>
    </EncryptedData>
</fns:foo>

Or you can change the default element several times removing all the prefixes 或者您可以多次更改默认元素,以删除所有前缀

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Liquid XML 2014 Developer Bundle Edition 12.1.2.5004 (http://www.liquid-technologies.com) -->
<foo xmlns="http://www.foo.org/Foo">
    <EncryptedData xmlns='http://www.w3.org/2001/04/xmlenc#'>
        <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
        <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
            <KeyName>John Smith</KeyName>
        </KeyInfo>
        <CipherData>
            <CipherValue>DEADBEEF</CipherValue>
        </CipherData>
    </EncryptedData>
</foo>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM