You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Mikael Svenning <mi...@gmail.com> on 2013/01/04 13:23:35 UTC

Validating XML with attributes in namespace "xml"

Hello,
I have a question regarding namespaces for attributes, and how to declare
such attributes in an XML schema.

The reason that I want to use namespaces for an attribute is that I use XML
DSig,
and the signature parts should be specified with an "ID" attribute.

The name of the attribute that specify the identification could have any
name, and some possible choices are "ID", "Id" or "id".

However, there seems to be a recommendation to use "xml:id", rather than
anything else such as "ID".

This is for example described in the following page:
http://www.w3.org/TR/xml-id/

This works fine for DSig signatures.
I am using "xmlsec1" for signing/verification in my C++ application, and I
am able to sign and verify the signature.

In the XML files, the id is specified like this:

<elm:MyElement xml:id="MyName" OtherAttribute="SomeValue">

Note that "xml:id" is an attribute in a namespace, which is rarely used
although legal XML.
However, the XML files should also be validated against a schema with
Xerces, and it is there I have some problems.

The problem is probably that I do not specify the schema correctly, rather
than a problem in Xerces-C.


I have tried to specify the attribute name as "xml:id" in the scheme like
this:
==========================================
                        <xs:attribute name="xml:id" use="required">
                                <xs:simpleType>
                                        <xs:restriction base="xs:string">
                                                <xs:enumeration
value="MyName"/>
                                        </xs:restriction>
                                </xs:simpleType>
                        </xs:attribute>
==========================================


However, when I try to validate the document, I get the following error
message:
==================================
Error at file XMLParserInput, line 1, char 441
  Message: attribute '{http://www.w3.org/XML/1998/namespace}id' is not
declared for element 'Routing'
==================================

My XML document has an "xml:id" attribute, but the Xerces validator does
not seem to think
that this attribute is declared according to the schema.

My question now is how I should write the XML schema to make it accept
"xml:id"?

I have searched on the net, and I have got some hints, for example this:

http://xsd.stylusstudio.com/2004Oct/post01004.htm

But my XML schema is more complicated, and consists of several xsd files
and multiple namespaces,
so I have not been able to make it validate with Xerces.


My XML file declares something similar to the following:
===============================
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-env
elope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:qwerty="
http://www.mycompany
.se/qwert" xmlns:abcd="http://www.mycompany.se/abcd">
===============================

The schema file(s) declares information similar to this:
===============================
<xs:schema xmlns:abcd="http://www.mycompany.se/abcd" xmlns:xs="
http://www.w3.org/2001/XMLSchem
a"  targetNamespace="http://www.mycompany.se/abcd"
elementFormDefault="qualified" attributeFor
mDefault="unqualified">
===============================

Can you give some hints how I should declare the XML schema to validate the
XML file with xml:id?


Regards
/Mikael