Hi guys I have a simple XML file with this structure
... ...
<Fields>
<Field name="MainJob.Id" value="t066_id">
<Description nullable="false" type="System.Int32" />
</Field>
What I have actually is this XSD file description:
<xs:element minOccurs="0" maxOccurs="unbounded" name="Fields">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Field">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Description">
<xs:complexType>
<xs:attribute name="nullable" type="xs:string" use="required" /> <xs:attribute name="type" type="xs:string" use="required" />
<xs:attribute name="minLength" type="xs:string" use="optional" />
<xs:attribute name="maxLength" type="xs:string" use="optional" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="value" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
How I can define two only available values for the attribute nullable, like 'true' and 'false'?
If I nest a SimpleType inside the attribute the .XSD file is not valid anymore.
thank you
Type should be not xs:string but xs:boolean for your example, or you can use enumeration (example).
You can add a simpleType like so:
<xs:simpleType name="TrueOrFalse">
<xs:restriction base="xs:string">
<xs:enumeration value="false"/>
<xs:enumeration value="true"/>
</xs:restriction>
</xs:simpleType>
and then change your nullable to:
<xs:attribute name="nullable" type="TrueOrFalse" use="required" />
Marc
Related
I have a XSD definition which looks like this:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="ARTICLES">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="ARTICLE">
<xs:complexType>
<xs:sequence>
<xs:element name="NAME" type="xs:string" />
<xs:element name="TYPE" type="xs:unsignedByte" />
<xs:element name="LENGTH" type="xs:unsignedByte" />
<xs:element name="WIDTH" type="xs:unsignedShort" />
<xs:element name="HEIGHT" type="xs:unsignedShort" />
<xs:element maxOccurs="unbounded" name="PRICELIST">
<xs:complexType>
<xs:sequence>
<xs:element name="SALESCONTRACT" type="xs:string" />
<xs:element name="PRICE" type="xs:decimal" />
<xs:element name="VAT" type="xs:unsignedByte" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
An XML can contain a collection of ATRICLES and each ARTICLE can have 1 or more PRICELIST entries
Now I would like to take an element and restrict the value entries. i.e. With a regex or numbers only or in length.
With simpletype I found lots of examples that work with a pattern tag.
How would this work with complex types?
Regards,
Rick
You can simply apply all of those examples you've found using xs:simpleType to any of the parts of ARTICLE that you wish to further constrain. For example, to limit NAME to be of maximum length of 32 characters:
<xs:element name="NAME">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="32"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Hello I have a problem with Oracle XMLDB Express Edition 10g.
I am trying to register a fully valid and working .xsd Schema via dbms_xmlschema.registerSchema, but keep getting
ORA-01741: illegal zero-length identifier
I have tried everything: triplechecked my xsd and query code.
There were a couple of topics on Oracle forums but there were no answers.
Please help.
Here is my code:
begin
dbms_xmlschema.registerSchema(
'opta',
'<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.example.org/opta/" targetNamespace="http://www.example.org/opta/">
<xs:element name="Document">
<xs:complexType>
<xs:sequence>
<xs:element name="Order" type="tns:Order" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Order">
<xs:sequence>
<xs:element name="Products" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Product" type="tns:Product" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Date" type="xs:date" minOccurs="1"/>
<xs:element name="Client" type="tns:Client" minOccurs="1"/>
</xs:sequence>
<xs:attribute name="id" type="xs:int"/>
</xs:complexType>
<xs:complexType name="Product">
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Price" type="xs:int"/>
<xs:element name="Amount" type="xs:int"/>
<xs:element name="Producer" type="tns:Producer"/>
<xs:element name="Type" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:int"/>
</xs:complexType>
<xs:complexType name="Producer">
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Organization" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Client">
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Organization" type="xs:string"/>
<xs:element name="Country" type="xs:string"/>
<xs:element name="City" type="xs:string"/>
<xs:element name="Address" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
');
end;
I'm trying to make just one adapter for every type of element, so I created a bindings.xml file:
<jxb:bindings node="//xs:attribute[#type='Id']"
so, my intention is to address to every attribute of type "Id".
Problem is that xjc tells me "too many target nodes(3)" ... but it's just what I want!!
Try to add multiple="true" attribute:
<jxb:bindings multiple="true" node="//xs:attribute[#type='Id']"
I end up with a similar problem "too many target nodes(3)" however could not find any answer on any of the sites...Posting the solution which I found after lots of trail and error...Basic idea to solve "too many target nodes(3)" is to give complete XPATH of the node which is multiple in your XSD.
Below is my XSD:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="document">
<xs:complexType>
<xs:sequence>
<xs:element name="asset">
<xs:complexType>
<xs:sequence>
<xs:element name="attribute" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="string" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="value" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="date" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="value" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="array" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="struct" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="field" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="integer" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:byte" name="value"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="assetreference" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="type"/>
<xs:attribute type="xs:long" name="value"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="name" use="optional"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="integer" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:long" name="value"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="file" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="name" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="integer" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:short" name="value"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="name" use="optional"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:long" name="id"/>
<xs:attribute type="xs:string" name="type"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
and below is the JAXB binding file which is working for above XSD:
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.1">
<bindings schemaLocation= "../assetproduct.xsd" version="1.0">
<!-- Customise the package name
<schemaBindings>
<package name="com.example.schema"/>
</schemaBindings> -->
<!-- rename the value element -->
<bindings node="//xs:element[#name='document']">
<bindings node="//xs:element[#name='asset']">
<bindings node="//xs:element[#name='attribute']">
<bindings node="//xs:element[#name='string']">
<bindings node=".//xs:attribute[#name='value']">
<property name="ValueAttribute"/>
</bindings>
</bindings>
<bindings node="//xs:element[#name='date']">
<bindings node=".//xs:attribute[#name='value']">
<property name="ValueAttribute"/>
</bindings>
</bindings>
<bindings node="//xs:element[#name='array']">
<bindings node=".//xs:element[#name='struct']">
<bindings node=".//xs:element[#name='field']">
<bindings node=".//xs:element[#name='integer']/xs:complexType">
<bindings node=".//xs:attribute[#name='value']">
<property name="ValueAttribute"/>
</bindings>
</bindings>
<bindings node=".//xs:element[#name='assetreference']">
<bindings node=".//xs:attribute[#name='value']">
<property name="ValueAttribute"/>
</bindings>
</bindings>
</bindings>
</bindings>
</bindings>
<bindings node=".//xs:element[#name='array']/xs:complexType/xs:sequence/xs:element[#name='integer']">
<bindings node=".//xs:attribute[#name='value']">
<property name="ValueAttribute"/>
</bindings>
</bindings>
<bindings node="//xs:element[#name='attribute']/xs:complexType/xs:sequence/xs:element[#name='integer']">
<bindings node=".//xs:attribute[#name='value']">
<property name="ValueAttribute"/>
</bindings>
</bindings>
</bindings>
</bindings>
</bindings>
</bindings>
</bindings>
when I want to validate my xsd file, I got this error
cos-nonambig: "my xsd file":layout and "my xsd file":layout (or elements from their substitution group) violate "Unique Particle Attribution". During validation against this schema, ambiguity would be created for those two particles.
and refers me to this tag
<xs:complexType name="pageType">
<xs:choice>
<xs:element type="main:layoutType" name="layout" minOccurs="0" maxOccurs="1"/>
<xs:group ref="main:WidgetsGroup" maxOccurs="unbounded" minOccurs="0"/>
</xs:choice>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="layout"/>
<xs:attribute type="xs:string" name="dataModel"/>
<xs:attribute type="xs:string" name="domain"/>
</xs:complexType>
what is the problem? and how could I fix it?
I've solved it by inserting WidgetGroup contents to my xsd as :
<xs:complexType name="pageType">
<xs:choice>
<xs:element type="main:layoutType" name="layout" minOccurs="0" maxOccurs="1"/>
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element name="spinner" type="main:SpinnerType" minOccurs="0"/>
<xs:element name="datePicker" type="main:DatePickerType" minOccurs="0"/>
<xs:element name="button" type="main:ButtonType" minOccurs="0"/>
<xs:element name="combo" type="main:ComboBoxType" minOccurs="0"/>
<xs:element name="checkBox" type="main:CheckBoxType" minOccurs="0"/>
<xs:element name="radioButton" type="main:RadioButtonType" minOccurs="0"/>
<xs:element name="image" type="main:ImageType" minOccurs="0"/>
<xs:element name="label" type="main:LabelType" minOccurs="0"/>
<xs:element name="listBox" type="main:ListBoxType" minOccurs="0"/>
<xs:element name="textBox" type="main:TextBoxType" minOccurs="0"/>
<!--<xs:element name="layout" type="main:layoutType" minOccurs="0"/>-->
</xs:choice>
</xs:sequence>
</xs:choice>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="layout"/>
<xs:attribute type="xs:string" name="dataModel"/>
<xs:attribute type="main:domainType" name="domain"/>
<xs:attribute type="xs:string" name="title"/>
</xs:complexType>
I have the following xml:
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Child name="MyType" compareMode="EQ">Child1</Child>
</Root>
Usually in order to verify such an xml one would use the following xml schema:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="Child">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="compareMode" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I want to limit values of a Child element and allow only the following: Child1, Child2 and Child3.
I know that usually restriction may be specified with the following schema:
<xs:restriction base="xs:string">
<xs:enumeration value="Child1"/>
<xs:enumeration value="Child2"/>
<xs:enumeration value="Child3"/>
</xs:restriction>
Which restriction is correct in the first case?
Does this answer your question?
Having both an attribute and a restriction on an element in xml schema
I was wrong, because I didn't test my answer. I edited it:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="ChildContent">
<xs:restriction base="xs:string">
<xs:enumeration value="Child1"/>
<xs:enumeration value="Child2"/>
<xs:enumeration value="Child3"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="Child">
<xs:simpleContent>
<xs:extension base="ChildContent">
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="compareMode" type="xs:string" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="Child" type="Child" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
or with restriction:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="Child">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="compareMode" type="xs:string" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="Child">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="Child">
<xs:enumeration value="Child1"/>
<xs:enumeration value="Child2"/>
<xs:enumeration value="Child3"/>
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
After hours spent with google: You cannot do this without named types.