Jump to content
Falthon

Root Element

Recommended Posts

I recently wrote my first XML schema, and I'm getting an error with the root element. After reading the tutorial and looking through the forums I'm still not clear on how a root element should be constructed. I don't have any background in programming or XML, and I think my understanding of the basic concepts is weak. I copied an existing XML file, modified it, and then used an automated tool to generate a schema from it; that may have been a mistake. The schema (which is called StimulusModel.xsd) starts with the following lines. <?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://sourceforge.net/projects/graframework"'>http://sourceforge.net/projects/graframework" xmlns="http://sourceforge.net/projects/graframework"'>http://sourceforge.net/projects/graframework" elementFormDefault="qualified">The XML file (Rose_Smell.xml) starts with the following. <?xml version="1.0" encoding="UTF-8" standalone="no"?><StimulusType xmlns="http://sourceforge.net/projects/graframework"'>http://sourceforge.net/projects/graframework" xmlns:xsi="http://sourceforge.net/projects/graframework StimulusModel.xsd">Should I have "encoding=UTF-8" or should I leave that out? That came from the XML file I copied, so perhaps I shouldn't have it. I assume standalone="no" since Rose_Smell.xml requires another XML file. Is this correct? Is it needed? I'm getting the following message. file:///../Rose_Smell.xml:2: parser warning : xmlns:xsi: 'http://sourceforge.net/projects/graframework StimulusModel.xsd' is not a valid URIwork" xmlns:xsi="http://sourceforge.net/projects/graframework StimulusModel.xsd"Perhaps I have more than I need in the root element? Should I delete some of it? Sorry for the newbie questions, and I appreciate any help you can provide.

Share this post


Link to post
Share on other sites

What you have with

xmlns:xsi="http://sourceforge.net/projects/graframework StimulusModel.xsd">

is to declare a namespace who's namespace URI is not a valid URI (because of the space). This is not how a schema is used. You first need to declare the XML schema namespace and use it's "schemaLocation" attribute to fetch the schema for that namespace as you have. This makes the final XML file:

<StimulusType xmlns="http://sourceforge.net/projects/graframework" xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://sourceforge.net/projects/graframework StimulusModel.xsd">

As for the standalone. I don't think it's needed, but I'm not sure of it's usage either. If your application (the one that processes the XML) requires another file with this one, it's up to that application to signal an error and you decide how to specify the required file. "standalone" can't know what else the XML requires.What I think it is for is that when a document is not standalone and it has a DTD, the DTD has to be parsed. Otherwise a parser can ignore the DTD if validation is not required and there are no named entities used.

Share this post


Link to post
Share on other sites

1. I think "encoding=UTF-8" is OK if you are using English as your language. In most cases, the alternative is "iso-8859-1".2. Start by writing the xml source file.3. Then write the xml schema, xsd file and possibly the stylesheet, xsl file.4. I prefer to use the prefix xsd for the Schema namespace and define the root element of the schema like this:<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">5. The stand-alone declaration, not required within the XML declaration, indicates whether the document requires outside resources, such as an external DTD. The value yes means the document is self-contained, and the value no indicates that external resources may be required. Documents that do not include a stand-alone declaration within the XML declaration, yet do include external resources, automatically assume the value of no.6.

Perhaps I have more than I need in the root element? Should I delete some of it?
Yes may be.

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...