Jump to content
broom

1 element - 2 definitions

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!

Share this post


Link to post
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.)

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...