xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mikael Svenning <mikael.svenn...@gmail.com>
Subject Validating XML with attributes in namespace "xml"
Date Fri, 04 Jan 2013 12:23:35 GMT
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
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:

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
                        <xs:attribute name="xml:id" use="required">
                                        <xs:restriction base="xs:string">

However, when I try to validate the document, I get the following error
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

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


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="
.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="
a"  targetNamespace="http://www.mycompany.se/abcd"
elementFormDefault="qualified" attributeFor

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


View raw message