Jump to content

1 element - 2 definitions


broom

Recommended Posts

hi,i have a little problem and hope that you can help me.this is the xml-element (parent) that i want to express as schema.it has two possible forms:

<parent>  1234</parent><parent>  <child1/>  <child2/></parent>

meaning. either, parent has a simple content (integer), or it has childelements (and no other content, so no mixed content)is it possible to express something like that in xml schema (v1.0) or is this impossible? i tried a choice between 2 definitions of the parent element which does not work since a type definition must be unique. :) any ideas.. anyone?my thx in advance!

Link to comment
Share on other sites

it's a start. i just have to figure out how to mix simpleContent and complexContent, which doesn't seem to work with the validators i used.btw. any tips for a good validator? (the example you directed my at is considered invalid by XMLSpy e.g.)

Link to comment
Share on other sites

it's a start. i just have to figure out how to mix simpleContent and complexContent, which doesn't seem to work with the validators i used.btw. any tips for a good validator? (the example you directed my at is considered invalid by XMLSpy e.g.)
W3schools references a validator in its XSD tutorial: http://www.w3.org/2001/03/webdata/xsvHowever --:)-- I like the Liquid XML Schema Validator(download) because you don't just give the URL, you can actually put in your code :) : Liquid XSD.
Link to comment
Share on other sites

tried a choice between 2 definitions of the parent element which does not work since a type definition must be unique. :) any ideas.. anyone?my thx in advance!
Can you post your XML? Your example fragment of <parent> etc is a bit abstract which makes it a tad difficult to tell exactly what you want to do.Below is something which may help anyway. It's an example of a schema that permits a choice within a complex type, where one of the choices is a plain string. But you do have to give the XML elements different names. Schema fragment:
  <xs:complexType name="Person">	<xs:sequence maxOccurs='unbounded'>		<xs:choice>			<xs:element name="Name" type='xs:string'/>			<xs:element name="FormattedName" type="FormattedName" />		</xs:choice>	</xs:sequence>  </xs:complexType>	<xs:complexType name='FormattedName'>		<xs:sequence>			<xs:element name="FirstName" type='xs:string'/>			<xs:element name="LastName" type='xs:string'/>		</xs:sequence>	</xs:complexType>

And the XML fragment to go with it:

  <Name>Waldo Pepper</Name>  <Name>Red Pepper</Name>  <FormattedName>	<FirstName>Green</FirstName>	<LastName>Pepper</LastName>  </FormattedName>

Hope this helps but if not, as I said, post your XML and it may shed more light on what's needed.

Link to comment
Share on other sites

thanks for your answer reg edit. for the concrete example: the problem is that the <parent>.. XML that i've posted is exactly what i need (my elements here have different names, but i thought naming them parent and child made the problem more obvious).this is what i have:

<Value type="integer>134</Value><Value type="tuple">   <Value type="string">hello</Value>   <Value type="string">world</Value>   <Value type="float">1.2</Value></Value>

so the value element must either be a simple type, or have value child elements, but not both.right now i'm just using mixed content and then let the application check if that particular <parent> has the correct content.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...