comp.lang.ada
 help / color / mirror / Atom feed
* XML/Ada schema validation and XML namespaces
@ 2013-04-08 19:58 J Kimball
  2013-04-08 20:00 ` J Kimball
  2013-04-09 11:45 ` Simon Wright
  0 siblings, 2 replies; 5+ messages in thread
From: J Kimball @ 2013-04-08 19:58 UTC (permalink / raw)


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




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-04-10 19:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-08 19:58 XML/Ada schema validation and XML namespaces J Kimball
2013-04-08 20:00 ` J Kimball
2013-04-09 11:45 ` Simon Wright
2013-04-10 17:42   ` J Kimball
2013-04-10 19:56     ` Simon Wright

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