How to use xml:id

This should cover W3C XML Schema, Relax NG and DTD related problems.
dgc03052
Posts: 4
Joined: Thu Oct 06, 2005 7:01 am

How to use xml:id

Post by dgc03052 »

I've been trying to use xml:id in a schema, and keep getting messages like "Description: E src-resolve.4.2: Error resolving component 'xml:id'. It was detected that 'xml:id' is in namespace 'http://www.w3.org/XML/1998/namespace', but components from this namespace are not referenceable from schema document 'file:/C:/Devel/foo.xsd'. If this is the incorrect namespace, perhaps the prefix of 'xml:id' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'file:/C:/Devel/foo.xsd'."

This is for using it inside a type definition like:
<xs:attribute ref="xml:id" use="optional"/>

I see that xml:id is defined in the xml.xsd file in the program files tree - how do I define something a schema to use it that will validate (even if the xml:id spec requirements of uniqueness isn't enforced)?

Thanks,
dgc
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi,

As the error message says you need to import the schema for that namespace. Add something like below to your schema:

<import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="http://www.w3.org/2001/03/xml.xsd"/>

Best Regards,
George
dgc03052
Posts: 4
Joined: Thu Oct 06, 2005 7:01 am

xml:id

Post by dgc03052 »

That would work if it was just any old namespace, but the xml namespace is already defined and available. Adding an explicit import (xs:import) will change the details, but still fail to recognise xml:id (which IS available at that URL).

Note that the approved xml:id recomendation is available at:
http://www.w3.org/TR/2005/REC-xml-id-20050909/

Adding the xs:import just gets you to:
SystemID: N:\Temp\liberty-idwsf-secmech_test.xsd
Location: 23:48
Description: E src-resolve: Cannot resolve the name 'xml:id' to a(n) 'attribute declaration' component.
URL: http://www.w3.org/TR/xmlschema-1/#src-resolve

SystemID: N:\Temp\liberty-idwsf-secmech_test.xsd
Location: 23:48
Description: E s4s-elt-invalid-content.1: The content of 'ProviderInfoConfirmationDataType' is invalid. Element 'attribute' is invalid, misplaced, or occurs too often.

Try loading the following (with or without the xs:import of xml - both ways will fail) - this is an extremely stripped down example.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:sec="urn:liberty:sec:2005-11"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
targetNamespace="urn:liberty:sec:2005-11"
elementFormDefault="qualified"
attributeFormDefault="unqualified">

<xs:import namespace="urn:oasis:names:tc:SAML:2.0:assertion"
schemaLocation="http://docs.oasis-open.org/security/sam ... on-2.0.xsd"/>
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#"
schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-c ... schema.xsd"/>
<xs:import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="http://www.w3.org/2001/03/xml.xsd"/>

<xs:annotation>
<xs:documentation>Liberty ID-WSF Security Mechanisms Specification XSD</xs:documentation>
<xs:documentation>
Text goes here

</xs:documentation>
</xs:annotation>
<xs:complexType name="ProviderInfoConfirmationDataType" mixed="false">
<xs:complexContent mixed="false">
<xs:restriction base="saml2:SubjectConfirmationDataType">
<xs:sequence>
<xs:element ref="saml2:AssertionIDRef"/>
<xs:element ref="saml2:Issuer"/>
<xs:element name="IssueInstant" type="xs:dateTime"/>
<xs:element ref="ds:Signature" minOccurs="0"/>
</xs:sequence>
<xs:attribute ref="xml:id" use="optional"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:schema>
dgc03052
Posts: 4
Joined: Thu Oct 06, 2005 7:01 am

xml:id

Post by dgc03052 »

And yes, I know it is already a feature request (http://www.oxygenxml.com/forum/ftopic788.html), but I don't see any answer for a schedule there....
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi,

The xml:id was added in a recent version of xml.xsd. The xml.xsd is available at a few URLs, there are stable URLs for each release of xml.xsd and one URL that shows the latest version. If you change the import as below:

<xs:import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="http://www.w3.org/2001/xml.xsd"/>

then you will get the latest schema that contains xml:id and your schema will be valid. It seems that the stable URL for the last xml.xsd is not generally available, it requires W3C credentials: http://www.w3.org/2005/08/xml.xsd

My comment on the forum entry you quote was that if there is no schema then we cannot determine fields that are ID references so from an editor point of view there is nothing it can do with the collected ID values, it will just collect them but it cannot offer them for content completion. If you have a schema then oXygen will surely offer the ID values for IDREF and IDREFS values through content completion. Note that the ID values are collected during validation so you need to perform at least one Validate action in order to have ID values collected.

Best Regards,
George
dgc03052
Posts: 4
Joined: Thu Oct 06, 2005 7:01 am

xml:id

Post by dgc03052 »

Thank you,
I have contacted the w3c, and gotten the permissions issues addressed (or at least they seem to be, although there still is some confusion over what is "right"). There are still some minor issues with what is there (like the documentation still tells you to import the 2001/03 version), but this helps immensely.

dgc
Post Reply