This is an xml example I want to be able to validate with my selfmade schema.
The whole EncryptedData
part is actually syntax of the XML Encryption specification.
<?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 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. I need to prefix all the XML Encryption elements with namespaces as I imported them.
<?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? 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>