Jump to content

How to associate a Schema with an XML document(?)


sampsondaniel

Recommended Posts

I've studied the tutorials on w3schools, and elsewhere. The one thing I keep missing is how to associate an XML file with its Schema.Here is the tutorial's schema:<?xml version="1.0"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"targetNamespace="http://www.w3schools.com"xmlns="http://www.w3schools.com"elementFormDefault="qualified"><xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType></xs:element></xs:schema>And the following is the tutorial's XML document:<?xml version="1.0"?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>I am missing something so embarrassingly fundamental. Please help.

Link to comment
Share on other sites

It's just a bit further down the same page (http://www.w3schools.com/schema/schema_howto.asp).Here is the snippet:

This XML document has a reference to an XML Schema:<?xml version="1.0"?><notexmlns="http://www.w3schools.com"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.w3schools.com note.xsd"><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>

Link to comment
Share on other sites

Thank you for your reply!If my schema is located in a local folder, do I show the path to that local folder as the location?For example:<notexmlns="http://www.w3schools.com"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="C:\Documents and Settings\projectus\My Documents MySchema.xsd">(I am very new to XML, and need to learn quickly at work. I have been provided with a schema from a client, and need to record our information with XML.)

It's just a bit further down the same page (http://www.w3schools.com/schema/schema_howto.asp).Here is the snippet:
This XML document has a reference to an XML Schema:<?xml version="1.0"?><notexmlns="http://www.w3schools.com"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.w3schools.com note.xsd"><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>

Link to comment
Share on other sites

I have been provided with a schema. Now I need to figure out a way for a Q&A person in a manufacturing plant to enter data on a form that does not yet exist. I have to make that form. I don't only need to make an xml file; I need to display an xml file that accepts user input. I think what I need is XHTML... anyone think that's correct? For example, take the tutorial's example above <note.xml>. I need an xml form that a user can actually enter information between the tags, not an xml document that just shows a note.XML must be used, accoring to a contract.I just can't seem to learn how to make an xml document for data entry. It's the interactive part that gets me confused. I would think that an Excel spreadsheet would make sense, or an HTML table, with each cell following the rules of the schema, but as soon as I start thinking about someone else needing to "fill out" the document, my head starts spinning. For example, the Q&A person is going to walk up to a PC and open...open what? A Web page? An Excel spreadsheet? A .txt?I am so confused.

Link to comment
Share on other sites

I believe I've begun to solve my problem, so in case anyone has had similar problems with learning XML, I'll post it here.Use a WYSIWYG to create your stylesheet if you are not an ace with HTML code. I used Dreamweaver to write my code for me. Copy and save the code for use as your style.I didn't select CSS because I remember reading that it has some limitations, but I can't remember what they are.Cheers.

Link to comment
Share on other sites

Guest fantasia74

On a similar vein: A client wants to "grab" information from postings thatmay be phrased slightly differently at different sites.Example: Last Name vs. Family Name.Off the top of my head, I can't think of a way that XML would do this, by might not SQL be able to handlean "OR" situation?Thanks,Fantasia74

Link to comment
Share on other sites

Some of the stuff written here is pretty confusing, so my post might probably sound as an offtopic one...Let me explain how this mechanism should work...1. Define an XML language and a schema for it so others could create working XML documents. Apparently, that's done already.2. (Optional) Describe each of your decisions and provide a short tutorial as to how manually to create an XML file that corresponds to the Schema. Essential if you as a creator don't know your clients directly.-It seems you are missing this step, which makes you think you need to learn Schema. Read below, and you'll see that's not necessary-Now there is the usage path. Scince this XML requres a form, then here's the thing. Choose the type of form you'll create. The best choise to go with is XForms. With it, you simply1. Define the XML scructure on the client side.2. The only thing you need to do on the server side is to run a single command that will load the Schema and validate the input with it.3. If the output is valid, write it, if not, return the user to the form with an error message. Generating usefull error messages is another thing I'm not sure how to do, but if you have a deadline, that might not be an issue.If you choose ordinary forms, the situation get's a bit more trickier.1. Create the HTML form with it's fields and all.2. Use some JavaScript to validate the form's simpler parts on the client side to save the server from extra processing. This includes string lenght, mix and max values, but not more complex stuff which only the Schema could define.3. On the server, generate an XML from the post data by enclosing each field's data in the appropriate tags. For example in PHP, this might be something like

$element = '<element>' . $_POST['element'] . '</element>';

4. After the XML is generated as expected, execute the exact same command mentioned for the XForms in order to validate the generated XML against the Schema.5. Again, if it validates, write it and if not, promt the user for alterations.Note that XForms is not supported natively in today's browsers. The only browser which I know has such a native support is XSmiles. Also note that XHTML 1.0 pages that use XForms will not validate anymore.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...