# Have a couple XML questions, re: Schemas

**URL:** <https://boards.straightdope.com/t/have-a-couple-xml-questions-re-schemas/178400>\
**Category:** Factual Questions\
**Created:** [May 29, 2003, 11:53pm UTC](https://boards.straightdope.com/t/have-a-couple-xml-questions-re-schemas/178400 "2003-05-29T23:53:12Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![LilShieste](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@LilShieste](https://boards.straightdope.com/u/LilShieste)\
**Post date:** [May 29, 2003, 11:53pm UTC](https://boards.straightdope.com/t/have-a-couple-xml-questions-re-schemas/178400/1 "2003-05-29T23:53:12Z")

</div>

Well, short version of the story: I am dynamically creating an XML file that is going to describe a directory structure (i.e. folders, subfolders, etc). Obviously, creating the XML file isn’t too bad… but I am having a few problems understanding some things about Schemas. Primarily with namespaces.

I have found a bit of documentation on the web about Schemas, but nothing that has really helped anything “click”, if you know what I mean (it’s really frustrating). I also have a book on XML, but it was before the whole “Schema” era came along-- it focuses on DTDs.

Here are links to the files:  
[XML file](http://www.umr.edu/~joseph/XML/crap.xml)[Schema File](http://www.umr.edu/~joseph/XML/directory.xsd) .

I would greatly appreciate any help/feedback anyone can give me on my files… even if it’s condescending- at this point I don’t care. I just want to understand Schemas!! 🙂  
LilShieste

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [May 30, 2003, 12:54am UTC](https://boards.straightdope.com/t/have-a-couple-xml-questions-re-schemas/178400/2 "2003-05-30T00:54:52Z")

</div>

There are programs, such as XMLSpy, that can automatically convert a DTD to a schema. I would use those, as some one-liners in a DTD can be very involved as schemas.

---

<div class="post-metadata">

**Author:** ![LilShieste](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@LilShieste](https://boards.straightdope.com/u/LilShieste)\
**Post date:** [May 30, 2003, 1:08am UTC](https://boards.straightdope.com/t/have-a-couple-xml-questions-re-schemas/178400/3 "2003-05-30T01:08:16Z")

</div>

Thanks for the idea, **ultrafilter** – that is definitely something to keep in mind. Even still, I really want to just figure this namespace thing out.

Heck, for all I know, I may even be doing it right…😕  
LilShieste

---

<div class="post-metadata">

**Author:** ![LordVor](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@LordVor](https://boards.straightdope.com/u/LordVor)\
**Post date:** [May 30, 2003, 1:22am UTC](https://boards.straightdope.com/t/have-a-couple-xml-questions-re-schemas/178400/4 "2003-05-30T01:22:41Z")

</div>

I think you’re close. You need a minOccurs=1 maxOccurs=1 on your name element of the directory, and it needs to be outside of your sequence, since every directory has to have one name and exactly one name. Then your file and directory children of directory and root have to have a minOccurs=1.

I’m not positive that sequence is the right complexType you want, but I’d need references I have at work to tell you for sure.

-lv

---

<div class="post-metadata">

**Author:** ![LordVor](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@LordVor](https://boards.straightdope.com/u/LordVor)\
**Post date:** [May 30, 2003, 1:23am UTC](https://boards.straightdope.com/t/have-a-couple-xml-questions-re-schemas/178400/5 "2003-05-30T01:23:51Z")

</div>

Ack! Then your file and directory children of directory and root have to have a minOccurs=0, because not every directory will have a file in it or a directory in it.

-lv

---

<div class="post-metadata">

**Author:** ![LilShieste](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@LilShieste](https://boards.straightdope.com/u/LilShieste)\
**Post date:** [May 30, 2003, 2:50am UTC](https://boards.straightdope.com/t/have-a-couple-xml-questions-re-schemas/178400/6 "2003-05-30T02:50:21Z")

</div>

I will try adding those attributes and see what happens, thanks **LordVor**.

And yeah, the recursive nature of this schema doesn’t make things any easier. My fault. 🙂  
LilShieste

---

<div class="post-metadata">

**Author:** ![LilShieste](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@LilShieste](https://boards.straightdope.com/u/LilShieste)\
**Post date:** [May 30, 2003, 2:52am UTC](https://boards.straightdope.com/t/have-a-couple-xml-questions-re-schemas/178400/7 "2003-05-30T02:52:11Z")

</div>

Oops… nevermind. I won’t add the attributes, since they don’t help me. hehe Yeah, time for another Code Red Mt. Dew.  
LilShieste

---

<div class="post-metadata">

**Author:** ![LordVor](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@LordVor](https://boards.straightdope.com/u/LordVor)\
**Post date:** [May 30, 2003, 4:13am UTC](https://boards.straightdope.com/t/have-a-couple-xml-questions-re-schemas/178400/8 "2003-05-30T04:13:06Z")

</div>

OK, my last try at this without my references from work:

I think you’re trying for something like:

\<dir:element name=“directory”\>  
\<dir:complexType\>  
\<dir:element ref=“name” /\>  
\<dir:sequence minOccurs=“0”; maxOccures=“Unbounded”\>  
\<dir:element ref=“directory” /\>  
\<dir:element ref=“file” /\>  
\</dir:sequence\>  
\</dir:complexType\>  
\</dir:element\>

That makes a directory a complexType with a required name field followed by 0 or more sequences of either directory or file. However, it might be saying 0 or more sequences of a directory element AND a file element, in which case sequence isn’t the right keyword, but I can’t find the right one from here.

Of course, the messageboard is eating my tabbing…

-lv

---

<div class="post-metadata">

**Author:** ![LilShieste](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@LilShieste](https://boards.straightdope.com/u/LilShieste)\
**Post date:** [May 30, 2003, 4:17am UTC](https://boards.straightdope.com/t/have-a-couple-xml-questions-re-schemas/178400/9 "2003-05-30T04:17:09Z")

</div>

Thanks for your help, **LordVor** , what you’re doing makes sense to me. Did you see anything wrong with my namespaces? Or was I worrying about nothing? 🙂  
LilShieste

---

<div class="post-metadata">

**Author:** ![LordVor](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@LordVor](https://boards.straightdope.com/u/LordVor)\
**Post date:** [May 30, 2003, 4:45am UTC](https://boards.straightdope.com/t/have-a-couple-xml-questions-re-schemas/178400/10 "2003-05-30T04:45:06Z")

</div>

I think the namespaces are fine…but that’s not my strong spot. I think you may be doing more than is technically necessary, because I could barely find anything on those keywords over at [xml.org](http://xml.org). Here’s the only example I could find:

\<logml xmlns=“[http://www.cs.rpi.edu/LOGML](http://www.cs.rpi.edu/LOGML)”  
xmlns:xsi=“[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)”  
xsi:schemaLocation=“[http://www.cs.rpi.edu/LOGML](http://www.cs.rpi.edu/LOGML)  
[http://www.cs.rpi.edu/~puninj/LOGML/logml.xsd](http://www.cs.rpi.edu/~puninj/LOGML/logml.xsd)”  
start\_date=“12/Oct/2000:05:00:05”  
end\_date=“12/Oct/2000:16:00:01”\>

It looks roughly like yours…

-lv

---

<div class="post-metadata">

**Author:** ![LilShieste](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@LilShieste](https://boards.straightdope.com/u/LilShieste)\
**Post date:** [May 30, 2003, 4:50am UTC](https://boards.straightdope.com/t/have-a-couple-xml-questions-re-schemas/178400/11 "2003-05-30T04:50:57Z")

</div>

ahhh ok. Yeah, most of my information was gathered from the W3C website(s) so… it probably is _un_necessary… for the most part.

Well, thanks again for all your help, **LordVor**. I think my revised XML and XSD files are now ready to work with, for any purposes I need to use it for anyway.  
LilShieste

---

<div class="post-metadata">

**Author:** ![LordVor](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@LordVor](https://boards.straightdope.com/u/LordVor)\
**Post date:** [May 30, 2003, 3:12pm UTC](https://boards.straightdope.com/t/have-a-couple-xml-questions-re-schemas/178400/12 "2003-05-30T15:12:03Z")

</div>

After checking references, I’m still unsure how namespaces work, but the other keyword I was thinking of would be “choice” instead of “sequence”, I think that’s what you really want, a 0-infinity repettition of a choice between files and directories.

-lv

---

<div class="post-metadata">

**Author:** ![LilShieste](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@LilShieste](https://boards.straightdope.com/u/LilShieste)\
**Post date:** [May 30, 2003, 4:05pm UTC](https://boards.straightdope.com/t/have-a-couple-xml-questions-re-schemas/178400/13 "2003-05-30T16:05:02Z")

</div>

oooOOOooo Now _that_ sounds like a handy-dandy element I can use. Thanks again!  
LilShieste

---

<div class="post-metadata">

**Author:** ![LordVor](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@LordVor](https://boards.straightdope.com/u/LordVor)\
**Post date:** [May 30, 2003, 4:51pm UTC](https://boards.straightdope.com/t/have-a-couple-xml-questions-re-schemas/178400/14 "2003-05-30T16:51:39Z")

</div>

'welcome.
