Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Strange XML nesting and schema validation

Reply
Thread Tools

Strange XML nesting and schema validation

 
 
Arthur
Guest
Posts: n/a
 
      02-03-2005
I've come across some strange xml, that I need to deal with, it looks
like this:-

<root>
<foo attr="1">Some random strange text.
<bar attr="2">blar</bar>
<bar attr="3">blar blar</bar>
<bar attr="4">blar blar blar</bar>
</foo>
</root>

Its the 'Some random strange text' in the between the foo tags along
with all the bar tags.
First of all, if the above actually legal well formed XML?

And if so, what would some schema look like to validate it?

I've tried something similar to this:-

....
<xs:element name="foo">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="attr" type="xs:int" use="required"/>
</xs:extension>
</xs:simpleContent>
<xs:choice>
<xs:element name="bar" minOccurs="0">
<xs:complexType>
<xs:attribute name="attr" type="xs:int" use="required"/>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
....

Buts this doesn't work.

Anyone got any ideas?

Arthur.
 
Reply With Quote
 
 
 
 
Priscilla Walmsley
Guest
Posts: n/a
 
      02-03-2005
Hi Arthur,

It's allowed - it's known as mixed content. I wouldn't recommend it for
anything other than free-form text (like books, HTML, etc.) but if you
have no control over it...

Here is a type that will validate it:

<xs:element name="foo">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="bar" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="attr" type="xs:int" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="attr" type="xs:int" use="required"/>
</xs:complexType>
</xs:element>

Hope that helps,
Priscilla

----------------------------------
Priscilla Walmsley
Author, Definitive XML Schema
http://www.datypic.com
----------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      02-03-2005
In article <lhpMd.228$(E-Mail Removed)>,
Arthur <(E-Mail Removed)> wrote:

>Its the 'Some random strange text' in the between the foo tags along
>with all the bar tags.
>First of all, if the above actually legal well formed XML?


Consider

<p>This is <b>bold</b><p>

This "mixed context" is perfectly normal when XML is used for marking
up text - which was the original purpose of SGML and XML - but is not
usually a good idea when it's used for representing data structures.

>And if so, what would some schema look like to validate it?


See http://www.w3.org/TR/xmlschema-0/#mixedContent

-- Richard
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
web.xml / XML schema issue, why do some XML schema attributes disappear asciz@starmail.com Java 3 02-20-2007 09:56 AM
Validation with XSD using XML::LibXML::Schema, and XML::Validator::Schema huntingseasonson@gmail.com Perl Misc 5 11-29-2006 12:37 PM
Problem with schema-validation and property "http://apache.org/xml/properties/schema/external-schemaLocation" Markus Java 1 11-23-2005 02:41 PM
Module.nesting -> Kernel#nesting Trans Ruby 10 09-16-2005 12:21 AM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM



Advertisments