473,657 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Another .dtd to xml-schema problem

Hello again, I'm having a new problem converting a dtd to an xml
schema. This once is a little bit more complicated than in my previous
question.

The following file validates correctly:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE books [
<!ELEMENT books (book*)>

<!ELEMENT book (author)>
<!ATTLIST book title CDATA #REQUIRED isbn CDATA #REQUIRED>

<!ELEMENT author EMPTY>
<!ATTLIST author name CDATA #REQUIRED>
]>
<books>
<book title="Winter's Heart" isbn="123456789 ">
<author name="Robert Jordan"/>
</book>
<book title="Paradise t" isbn="987654321 ">
<author name="Liza Marklund"/>
</book>
</books>

Now I want to convert the DTD to an xml schema. Here's my failed
attempt:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="books">
<xs:complexType >
<xs:sequence>
<xs:element name="book" minOccurs="0"
maxOccurs="unbo unded">
<xs:complexType >
<xs:attribute name="title" type="xs:string "
use="required"/>
<xs:element name="authors" minOccurs="1"
maxOccurs="1">
<xs:complexType >
<xs:attribute name="name" type="xs:string "
use="required"/>
</xs:complexType>
</xs:element>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
My validator complains:
Location: 9:20
Description: s4s-elt-invalid-content.1: The content of
'#AnonType_book books' is invalid. Element 'element' is invalid,
misplaced, or occurs too often.

How do I fix this error?

- Eric

Feb 21 '07 #1
3 5628
On 21 Feb, 13:55, "Eric Lilja" <mindcoo...@gma il.comwrote:
Hello again, I'm having a new problem converting a dtd to an xml
schema. This once is a little bit more complicated than in my previous
question.

The following file validates correctly:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE books [
<!ELEMENT books (book*)>

<!ELEMENT book (author)>
<!ATTLIST book title CDATA #REQUIRED isbn CDATA #REQUIRED>

<!ELEMENT author EMPTY>
<!ATTLIST author name CDATA #REQUIRED>
]>
...

Now I want to convert the DTD to an xml schema. Here's my failed
attempt:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="books">
<xs:complexType >
<xs:sequence>
<xs:element name="book" minOccurs="0"
maxOccurs="unbo unded">
<xs:complexType >
<xs:attribute name="title" type="xs:string "
use="required"/>
<xs:element name="authors" minOccurs="1"
maxOccurs="1">
<xs:complexType >
<xs:attribute name="name" type="xs:string "
use="required"/>
</xs:complexType>
</xs:element>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

My validator complains:
Location: 9:20
Description: s4s-elt-invalid-content.1: The content of
'#AnonType_book books' is invalid. Element 'element' is invalid,
misplaced, or occurs too often.

How do I fix this error?
The following bit looks a bit grim :-)

<xs:element name="book" minOccurs="0" maxOccurs="unbo unded">
<xs:complexType >
<xs:attribute name="title" type="xs:string " use="required"/
>
<xs:element name="authors" minOccurs="1" maxOccurs="1">
<xs:complexType >
<xs:attribute name="name" type="xs:string "
use="required"/>
</xs:complexType>
</xs:element>
</xs:complexType>
</xs:element>

I think it should be more like this:

<xs:element name="book" minOccurs="0" maxOccurs="unbo unded">
<xs:complexType >
<xs:sequence>
<xs:element name="authors" minOccurs="1"
maxOccurs="1">
<xs:complexType >
<xs:attribute name="name" type="xs:string "
use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="title" type="xs:string " use="required"/
>
</xs:complexType>
</xs:element>

(This is where having a schema editor really helps. Visual Studio
2003/5 suffice and I guess there are others. I'm not sure if the
Express editions support schema editing.)

BTW - by nesting all your definitions you are adopting what is called
a Russian Doll design. That's not all bad, but after a while you end
up having to buy a wider monitor! You could define your schemas along
the lines of:

<xs:element name="book" type="Book" minOccurs="0"
maxOccurs="unbo unded">
... other parts of your sequence...

...then as a separate global type...
<xs:complexTy pe type="Book">
<xs:sequence>
<xs:element name="authors" minOccurs="1" maxOccurs="1">
<xs:complexType >
<xs:attribute name="name" type="xs:string "
use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="title" type="xs:string " use="required"/>
</xs:complexType>

This is called venetian blind. It makes things a lot flatter, and
it's usually easier to see the sorts of mistakes that you had earlier.

You can see examples of venetian blind design in my own little
tutorial at:
http://www.tech-know-ware.com/lmx/xsd-overview.html

HTH,

Pete.
--
=============== =============== ===============
Pete Cordell
Tech-Know-Ware Ltd
for XML to C++ data binding visit
http://www.tech-know-ware.com/lmx
(or http://www.xml2cpp.com)
=============== =============== ===============

Feb 21 '07 #2
Hello and thanks again, Pete! My comments are below

On 21 Feb, 15:38, use...@tech-know-ware.com wrote:
On 21 Feb, 13:55, "Eric Lilja" <mindcoo...@gma il.comwrote:
Hello again, I'm having a new problem converting a dtd to an xml
schema. This once is a little bit more complicated than in my previous
question.
The following file validates correctly:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE books [
<!ELEMENT books (book*)>
<!ELEMENT book (author)>
<!ATTLIST book title CDATA #REQUIRED isbn CDATA #REQUIRED>
<!ELEMENT author EMPTY>
<!ATTLIST author name CDATA #REQUIRED>
]>
...
Now I want to convert the DTD to an xml schema. Here's my failed
attempt:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="books">
<xs:complexType >
<xs:sequence>
<xs:element name="book" minOccurs="0"
maxOccurs="unbo unded">
<xs:complexType >
<xs:attribute name="title" type="xs:string "
use="required"/>
<xs:element name="authors" minOccurs="1"
maxOccurs="1">
<xs:complexType >
<xs:attribute name="name" type="xs:string "
use="required"/>
</xs:complexType>
</xs:element>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
My validator complains:
Location: 9:20
Description: s4s-elt-invalid-content.1: The content of
'#AnonType_book books' is invalid. Element 'element' is invalid,
misplaced, or occurs too often.
How do I fix this error?

The following bit looks a bit grim :-)

<xs:element name="book" minOccurs="0" maxOccurs="unbo unded">
<xs:complexType >
<xs:attribute name="title" type="xs:string " use="required"/

<xs:element name="authors" minOccurs="1" maxOccurs="1">
<xs:complexType >
<xs:attribute name="name" type="xs:string "
use="required"/>
</xs:complexType>
</xs:element>
</xs:complexType>
</xs:element>

I think it should be more like this:

<xs:element name="book" minOccurs="0" maxOccurs="unbo unded">
<xs:complexType >
<xs:sequence>
<xs:element name="authors" minOccurs="1"
maxOccurs="1">
<xs:complexType >
<xs:attribute name="name" type="xs:string "
use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="title" type="xs:string " use="required"/

</xs:complexType>
</xs:element>
Thanks again, Pete! I would've gone crazy without you. What you pasted
enabled my schema to validate and my xml-file that use it. The
complete schema now looks like this (probably won't look good on
screen, I'm still using the "russian doll"-style):
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="books">
<xs:complexType >
<xs:sequence>
<xs:element name="book" minOccurs="0"
maxOccurs="unbo unded">
<xs:complexType >
<xs:sequence>
<xs:element name="authors" minOccurs="1"
maxOccurs="1">
<xs:complexType >
<xs:attribute name="name" type="xs:string "
use="required"/>
</xs:complexType< !-- authors complexType -->
</xs:element<!-- authors -->
</xs:sequence<!-- book sequence -->
<xs:attribute name="title" type="xs:string "
use="required"/>
</xs:complexType< !-- book complexType -->
</xs:element<!-- book -->
</xs:sequence<!-- books sequence -->
</xs:complexType< !-- books complexType -->
</xs:element<!-- books -->
</xs:schema>

Looks OK?
>
(This is where having a schema editor really helps. Visual Studio
2003/5 suffice and I guess there are others. I'm not sure if the
Express editions support schema editing.)
I am typing my schemas in emacs which gives syntax coloring and
indenting but not much else. I will try the VS xml editor as you
suggested.
>
BTW - by nesting all your definitions you are adopting what is called
a Russian Doll design. That's not all bad, but after a while you end
up having to buy a wider monitor! You could define your schemas along
the lines of:

<xs:element name="book" type="Book" minOccurs="0"
maxOccurs="unbo unded">
... other parts of your sequence...

...then as a separate global type...
<xs:complexTy pe type="Book">
<xs:sequence>
<xs:element name="authors" minOccurs="1" maxOccurs="1">
<xs:complexType >
<xs:attribute name="name" type="xs:string "
use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="title" type="xs:string " use="required"/>
</xs:complexType>

This is called venetian blind. It makes things a lot flatter, and
it's usually easier to see the sorts of mistakes that you had earlier.

You can see examples of venetian blind design in my own little
tutorial at:
http://www.tech-know-ware.com/lmx/xsd-overview.html
Yeah, I will probably need to adopt a new style soon.
>
HTH,

Pete.
--
Thanks so much, Pete!

- Eric
Feb 21 '07 #3
On Feb 21, 4:39 pm, "Eric Lilja" <mindcoo...@gma il.comwrote:
On 21 Feb, 15:38, use...@tech-know-ware.com wrote:
(This is where having a schema editor really helps. Visual Studio
2003/5 suffice and I guess there are others. I'm not sure if the
Express editions support schema editing.)

I am typing my schemas in emacs which gives syntax coloring and
indenting but not much else. I will try the VS xml editor as you
suggested.
Try nxml-mode. It has support for relax ng schemas to validate on-the-
fly.
I think XML Schema is included from the start.

Feb 22 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1530
by: Chris | last post by:
Hi, Maybe I've got a strange question. I've got a XML document (main.xml) with several nodes. Additional I've another XML docuement (role.xml), with allowed nodes. In a XSL-File I just would like to extract nodes from the main.xml file, which were declared in role.xml. Example:
5
7078
by: Vanessa | last post by:
I have a question, is that any other way to retrieve data from another webpage besides using XML object? Because I am using XML object now but give me so much problems. If I used MSXML2.ServerXMLHTTP object, it gives me time out error: msxml3.dll error '80072ee2' The operation timed out If I used Microsoft.XMLHTTP object, it will hang IE!
2
4458
by: sp | last post by:
Hello Everybody, I need to convert xml that we get from sqlserver For xml auto to my own xml format using asp.net classes. Any ideas and suggestions would be appreciated. Thanks in Advance sp
2
1551
by: moonriver | last post by:
In a xml file, can we make reference to another xml file so that all contents of the latter xml file will be included into the first xml file? Had better give me an example for details.
1
1508
by: irene | last post by:
Hi, I am trying to send an existing xml file to another machine(in some other company). We seem to be able to set up the connection to each other, but when I send the file, they never receive it. What is the usual way to send an existing xml file to another machine,say http://somewhere.com by vb.net? It is web application. Thanks.
0
1149
by: dotnetnoob | last post by:
hello, let's say i have two xml file 1. myData1.xml <?xml version="1.0" encoding="UTF-8"?> <myRoot> <myDataInput Number="1" Type="0" Status="Off" ObjName="test"> <Properties Attr="0" Number="1" ObjName="test"> <Description/> </Properties>
4
1316
by: mattdaddym | last post by:
Hi all, I've taken a couple of hours to read what is available, and I still cannot figure out how to do a very simple task in vb .net...lol. All I need to do is read an xml file and parse out specific information based on simple criteria. Let's use this as the xml file: <?xml version="1.0" encoding="utf-8" ?> <sites>
0
297
by: pintu | last post by:
Hi..I posted my message earlier but it was not properly described..so am posting again. I am working in an application in which i hav to send the contents of an xml file(from my local machine) to another server(www.ups.com) as http-request.As response i will get another xml file from that server. So what i did is i had 1.collected the data by using webrequest and webresponse class's methods (like webreq.create,webreq.getresponse and...
20
3142
by: Johan | last post by:
How can I include one XML file into another XML file (on the client side, in Firefox)? I think XInclude is just what I need, but Firefox doesn't support it: https://bugzilla.mozilla.org/show_bug.cgi?id=201754 It seems I also can use an "external entity reference", but that depends on a DTD and I'm using XML Schema. Is it also possible with a Schema and how can I do it?
8
190
by: Jorge | last post by:
On Jun 5, 3:36 pm, sheldonlg <sheldonlgwrote: What's wrong with that ? I'd say that that's perfect. Why don't you like it this way ? But just for the sake of changing something : function postProcess(txt) { var s= document.getElementById('showEdit').style;
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8603
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7320
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1604
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.