comp.lang.ada
 help / color / mirror / Atom feed
From: J Kimball <nntp@kmbll.com>
Subject: Re: XML/Ada schema validation and XML namespaces
Date: Mon, 08 Apr 2013 15:00:38 -0500
Date: 2013-04-08T15:00:38-05:00	[thread overview]
Message-ID: <kjv7l6$flb$2@hugin.sparre-andersen.dk> (raw)
In-Reply-To: <kjv7i1$flb$1@hugin.sparre-andersen.dk>

There is a minor error in the XML schema. The correct schema is:

A schema (agent.xsd):

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="http://example.com/schemas/agent"
xmlns:agent="http://example.com/schemas/agent">
  <xs:element name="response" type="agent:agent-message"/>
  <xs:complexType name="agent-message">
    <xs:sequence>
      <xs:element ref="agent:message"/>
    </xs:sequence>
  </xs:complexType>
  <xs:element name="message" type="xs:string"/>
</xs:schema>

On 04/08/2013 02:58 PM, J Kimball wrote:
> Hello
> 
> I'm having the derndest time figuring out how to validate XML using
> namespaces against a schema with XML/Ada. I seem to recall that doing
> away with namespaces makes it work. After all the debug junk I don't
> care about scrolls past, I see:
> 
> Validation_Error: Attribute "xmlns:agent" invalid for type
> {http://singo1.com/schemas/agent}agent-message
> Exception name: SCHEMA.VALIDATORS.XML_VALIDATION_ERROR
> 
> it seems like an issue with XML/Ada. Can you tell me if I'm missing a
> feature to enable, something about XML that I'm missing or just wrong
> code or an example that is using namespaces that works?
> 
> Some XML (agent.xml):
> 
> <?xml version="1.0"?>
> 
> <agent:response xmlns:agent="http://example.com/schemas/agent">
>    <agent:message>Zerg</agent:message>
> </agent:response>
> 
> A schema (agent.xsd):
> 
> <?xml version="1.0" encoding="UTF-8"?>
> 
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified"
> targetNamespace="http://singo1.com/schemas/agent"
> xmlns:agent="http://example.com/schemas/agent">
>   <xs:element name="response" type="agent:agent-message"/>
>   <xs:complexType name="agent-message">
>     <xs:sequence>
>       <xs:element ref="agent:message"/>
>     </xs:sequence>
>   </xs:complexType>
>   <xs:element name="message" type="xs:string"/>
> </xs:schema>
> 
> For those who are so inclined, I generated the XML schema from a RelaxNG
> schema (agent.rng) with trang:
> 
> <?xml version="1.0"?>
> 
> <rng:grammar
>    xmlns:rng="http://relaxng.org/ns/structure/1.0"
>    xmlns:a="http://relaxng.org/ns/annotation/1.0"
>    xmlns:agent="http://example.com/schemas/agent"
>    datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
> 
>    <rng:start>
>       <rng:ref name="agent-response" />
>    </rng:start>
> 
>    <rng:define name="agent-response">
>       <a:documentation>A response from a client.</a:documentation>
> 
>       <rng:element name="agent:response">
>          <rng:ref name="agent-message" />
>       </rng:element>
>    </rng:define>
> 
>    <rng:define name="agent-message">
>       <a:documentation>A simple message.</a:documentation>
> 
>       <rng:element name="agent:message"><rng:data type="string"
> /></rng:element>
>    </rng:define>
> 
> </rng:grammar>
> 
> % trang agent.rng agent.xsd
> 
> agent.xml validates successfully against both schemas using jing and
> xmllint:
> 
> % jing agent.rng agent.xml
> % xmllint --relaxng agent.rng agent.xml
> % xmllint --schema agent.xsd agent.xml
> 




  reply	other threads:[~2013-04-08 20:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-08 19:58 XML/Ada schema validation and XML namespaces J Kimball
2013-04-08 20:00 ` J Kimball [this message]
2013-04-09 11:45 ` Simon Wright
2013-04-10 17:42   ` J Kimball
2013-04-10 19:56     ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox