Jump to content


  • Content Count

  • Joined

  • Last visited

Everything posted by JoshuaP

  1. Hi,I want to define a type in my XSD that will validate both the XML examples below. <!-- Example 1 --><my_root_node> <street_type>STREET</street_type></my_root_node> <!-- Example 2 --><my_root_node> <street_type> <street_type>STREET</street_type> <street_type_alias>ST</street_type_alias> </street_type></my_root_node> However I do not want to define a mixed type as I don't want the following XML example to be valid. <!-- XML --><my_root_node> <street_type>STREET <street_type>STREET</street_type> <street_type_alias>ST</street_type_alias> </street_type></my_root_node><!-- XSD --> <xs:complexType name="TYPE_street_type_COMPLEX2" mixed="true"> <xs:complexContent mixed="true"> <xs:restriction base="xs:anyType"> <xs:sequence> <xs:element minOccurs="0" name="street_type" type="xs:string" /> <xs:element minOccurs="0" name="street_type_alias" type="xs:string" /> </xs:sequence> </xs:restriction> </xs:complexContent> </xs:complexType> Also the above example fails when I put <xs:restriction base="xs:string"> which seems odd.ERRMSG: The <complexType> [TYPE_street_type_COMPLEX2], is of Type [http://www.w3.org/2001/XMLSchema:string].'>http://www.w3.org/2001/XMLSchema:string]. However [http://www.w3.org/2001/XMLSchema:string] is not defined as a root item (either a <complexType> or <simpleType>), within this schema or any included or imported schemas.I have tried a union, but this only worked with simple types.I have also thought of other ways to achieve the same thing, like with the example below, but wanted to avoid putting the street_type are an attribute. <my_root_node> <street_type type="STREET"> <street_type_alias>ST</street_type_alias> </street_type></my_root_node> Is there another way to have multiple definitions for one type? I have read some things on this site about substitutions but didn't really understand it. I basically want to join the two following type definitions together. <xs:simpleType name="TYPE_street_type_SIMPLE"> <xs:restriction base="xs:string" /> </xs:simpleType> <xs:complexType name="TYPE_street_type_COMPLEX"> <xs:sequence> <xs:element minOccurs="0" name="street_type" type="xs:string" /> <xs:element minOccurs="0" name="street_type_alias" type="xs:string" /> </xs:sequence> </xs:complexType> Can anyone help?Josh
  2. JoshuaP

    Schema Basic Syntax

    Just some elements in the wrong place and no namespace of others.Try this an see how you go. The subpages might be in the wrong spot, it wasn't quite clear from your post. <xsd:element name="Mybookmark"> <xsd:complexType> <xsd:sequence> <xsd:element name="info" type="xsd:string"/> <xsd:element name="author" type="xsd:string"/> <xsd:element name="id" type="xsd:string"/> <xsd:element name="company" type="xsd:string"/> <xsd:element name="year" type="xsd:integer"/> <xsd:element name="shortdescription" type="xsd:string"/> <xsd:element name="Bookmark"> <xsd:complexType> <xsd:sequence> <xsd:element name="rating" type="integer"/> <xsd:element name="title" type="string"/> <xsd:element name="URL" type="string"/> <xsd:element name="postdate" type="xsd:date"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="subpages"> <xsd:complexType> <xsd:sequence> <xsd:element name="subtitle" type="string" /> <xsd:element name="subURL" type="string" /> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element>
  3. JoshuaP

    Nillable Elements

    Hi,I am having issues with elements with null values. The elements can be of many different types.Currently I have only be able to do this with a union on simple types, but I also want to allow complex types to be nulls. I have also tinkered with an XSLT that removes blank elements that works but I am after a neater approach.From all the documentation that I have read this is possible with the nillable="true" on the element tag but the program I am using (Liquid XML) say the xml is well formed but is invalid for the xsd. Some background on how the XML is created. A DB processes that is not smart enough to exclude null values in the tables creates the xml document. Where there is a null the tag is created as <exampletag /> and when there is a blank (not null) value the tag is create as exampletag></exampletag>.Can someone please confirm my xsd/xml is valid and the issue is with the program I am using to validate the xml, or tell me what I am doing wrong with my schema?<!-- Schema File mytest.xsd --><?xml version="1.0" encoding="utf-8" ?><xs:schema id="property" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="mydata"> <xs:complexType> <xs:sequence> <xs:element minOccurs="1" maxOccurs="2" name="nulltest" nillable="true"> <xs:simpleType> <xs:restriction base="xs:decimal" /> </xs:simpleType> </xs:element> </xs:sequence> </xs:complexType> </xs:element></xs:schema><!-- XML File mytest.xml--><?xml version="1.0" encoding="utf-8"?><mydata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="mytest.xsd"> <nulltest>1.1</nulltest> <nulltest></nulltest></mydata><!-- Error Message -->The 'nulltest' element is invalid - The value '' is invalid according to its datatype 'Decimal' - The string '' is not a valid Decimal value.Some clarification please!Josh
  • Create New...