[xml] validation and default attributes





Is it possible to validate an xml file with an xsd schema and have it insert the
missing default attributes as defined by the schema?

With xmllint it appears we can do it with a dtd schema but not the xsd schema.
Is this the case?

i.e. if we had the following xsd schema...

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
targetNamespace="http://www.w3schools.com";
xmlns="http://www.w3schools.com";
elementFormDefault="qualified">

<xs:simpleType name="urgencyType">
  <xs:restriction base="xs:string">
    <xs:enumeration value="Low"/>
    <xs:enumeration value="Normal"/>
    <xs:enumeration value="High"/>
    <xs:enumeration value="Critical"/>
  </xs:restriction>
</xs:simpleType>

<xs:element name="note">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="to" type="xs:string"/>
        <xs:element name="from" type="xs:string"/>
        <xs:element name="heading" type="xs:string"/>
        <xs:element name="body" type="xs:string"/>
      </xs:sequence>
      <xs:attribute name="urgency" type="urgencyType"
default="Normal"></xs:attribute>
    </xs:complexType>
</xs:element>
</xs:schema>



and the following xml file...

<?xml version="1.0"?>
<note
xmlns="http://www.w3schools.com";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://www.w3schools.com note.xsd">

<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>



then we were expecting the attribute called 'urgency' to be added to the element
called 'note'. Although xmllint declared the xml file valid, it doesn't seem to
handle default attributes.


The closest I could get to finding an answer was this
http://mail.gnome.org/archives/xml/2004-September/msg00005.html
but it is more than three years old

Cheers



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]