Jump to content

Xml Schema + Xml Docs


ellc

Recommended Posts

Hi,Anyone knows the proper syntax for inserting into Xml Docs ?Eg: I have an xsd name marker.xsdI tried >> <xmp:document xmlns:xmp="bookmark.xsd" then View XML file from my browser it looks ok, but when I tried to validate it on xmlme/validator it prompts error.Q1: How can I check individually my Schema is working before 'integrate it with any xml docs ?Q2: What would be the proper syntax to insert .xsd into xml files ?Regards, ells

Link to comment
Share on other sites

The proper syntax of associating an XML namespace with a schema is:

<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="bookmark.xsd">

As described in the W3Schools' XML Schema tutorial.This is however NOT "inser .xsd in xml files". It's about associating a namespace with a schema file that defines what's legal for it.In order to check if your Schema is valid or to check if a document validates against it, you need a Schema validator.In particular, for validating your XSD file, you should get a Schema editor that includes such a functionality. I'd reccomend Stylus Studio as one, but feel free to use any tool you can find.For validation of source documents against an XSD file, you'll use whatever you have at your disposal... but the browser is not it. AFAIK, no browser has a Schema validator. You can use PHP or any other server language to validate an XML file before you give it to a browser (or do something else with it).

Link to comment
Share on other sites

Hi boen_robot,Thanks for replying. I tried the validator (www.xmlme.com/validator.aspx) but couldn't really figure out what its trying to explained in the error portion.My bookmark.xml Heading:<?xml version="1.0"?><document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="bookmark.xsd">My bookmark.zsd Heading:<?xml version=”1.0”?><schema xmlns=”http://www.w3.org/2001/XMLSchema” targetNamespace="http://www.w3schools.com" elementFormDefault=”unqualified” attributeFormDefault=”unqualified”> The error indicates at Line 1 position 15 which I look at both files (.xml & .xsd, seems ok to me)[XML Error: System.Xml.XmlException: '”' is an unexpected token. The expected token is '"' or '''. Line 1, position 15. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args) at System.Xml.XmlTextReaderImpl.ThrowUnexpectedToken(String expectedToken1, String expectedToken2) at System.Xml.XmlTextReaderImpl.ParseXmlDeclaration(Boolean isTextDecl) at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlTextReader.Read() at System.Xml.Schema.Parser.StartParsing(XmlReader reader, String targetNamespace) at System.Xml.Schema.Parser.Parse(XmlReader reader, String targetNamespace) at System.Xml.Schema.XmlSchemaCollection.Add(String ns, XmlReader reader, XmlResolver resolver) at System.Xml.Schema.XmlSchemaCollection.Add(String ns, XmlReader reader) at Validator.Button1_Click(Object sender, EventArgs e)]- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

The proper syntax of associating an XML namespace with a schema is:
<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="bookmark.xsd">

As described in the W3Schools' XML Schema tutorial.This is however NOT "inser .xsd in xml files". It's about associating a namespace with a schema file that defines what's legal for it.In order to check if your Schema is valid or to check if a document validates against it, you need a Schema validator.In particular, for validating your XSD file, you should get a Schema editor that includes such a functionality. I'd reccomend Stylus Studio as one, but feel free to use any tool you can find.For validation of source documents against an XSD file, you'll use whatever you have at your disposal... but the browser is not it. AFAIK, no browser has a Schema validator. You can use PHP or any other server language to validate an XML file before you give it to a browser (or do something else with it).

Link to comment
Share on other sites

Looks to me like you're using smart quotes. Have you edited this file in MS Word by any chance?Use " for quotes instead of ”. Those are two different characters. Zoom in deeply with your browser on this very post (or your error message) and you'll see they look different as well.

Link to comment
Share on other sites

Hi Boen_Robot;Don't really get what you mean by smart code.. I edit those code in notepad though.Erm.. On looking carefully I get what you mean betwwen those double code < " > it just that I used normal keyboard from my laptop that's all. another thing I realised after passing those validator machine, I get funny character (chinese wording type, Eg: 攛, 攈) don't really knows what it means. And my .xsd heading becoming - <?xml version=?.0?>Q1. Any idea what is that ? Any Impact on the subsequent output ? What is the significance of it ?Q2. Do you think if I used xmlspy editor will be much easier (Well-Formness & Validating purpose) ?Q3. How do i check if my XSL is valid ? Q4. Not sure if this is the right location to pose this, anyway I needed to write a script language to open up a pop up windowfor the URL link provided in my xml docs, how can I insert those javascript (script.js) languaes into xml ?

Link to comment
Share on other sites

Normal keyboard or not, you must use " instead of ”. Do what you will (change your keyboard layout settings in Windows' regional settings or use a tool like "Character Map" to summon a quote when you need it), but use ".Your XML prolog should look like:

<?xml version="1.0"?>

(note the quotes again!!!)The prolog specified what version of XML you're using. There are currently only version 1.0 and 1.1, which are interchangeable in most cases, but you should still specify a version, especially if you plan to use 1.1 features. The XML prolog also specifies encoding. Even if you use UTF-8 (which AFAIK, is the default for XML 1.0), you should still include an XML prolog that ideally specifies this encoding explicitly to avoid possible encoding conflicts, like:

<?xml version="1.0" encoding="UTF-8"?>

It will likely be easier if you use a specialized editor. XML, unlike most client side languages, is very unforgiving (in this regard being more like server and desktop languages).You can't really check if your XSLT is valid other than by running it. If it executes at all, it's valid. Not producing any output (or wrong output) doesn't mean it's invalid.You don't open pop-ups in XML documents. XSLT transforms your XML into (X)HTML, and it's in that code where you can put JavaScript to open pop-ups. You can tell XSLT to insert the JavaScript at a certain point in the resulting (X)HTML in the same way that you can output any element and/or text.

Link to comment
Share on other sites

  • 2 weeks later...

Hi,Thanks for the reply I got it works by the way.. to run a JS, script in XML what are the conditions?I include my code xmldoc.load "myxml.xml" in my script.js but there wasnt any respond.Expected respond to hyperlink from my xml docs in the browser where I insert data types as anyURL.I even validate both my schema and xml file it was validated.Any settings on my browser required to activate a pop up window generating from clicking the hyper link ?Regards & God Bless, ellc

Link to comment
Share on other sites

Hi,Thanks for the reply I got it works by the way.. to run a JS, script in XML what are the conditions?I include my code xmldoc.load "myxml.xml" in my script.js but there wasnt any respond.Expected respond to hyperlink from my xml docs in the browser where I insert data types as anyURL.I even validate both my schema and xml file it was validated.Any settings on my browser required to activate a pop up window generating from clicking the hyper link ?Regards & God Bless, ellc
I'm not sure I understand the flow of things you're having. Do you have a link to that page?Also, what exactly are you trying to do? If I understand correctly:You have one XML that turned into XHTML.That XHTML has JavaScript, which is supposed to open myxml.xml in a new window.In that new window, myxml.xml.... should be transformed to XHTML by this or another XSLT file?
Link to comment
Share on other sites

Hi,Thanks for responding to my enquiry..I have 4 files together working namely (.xml, .xsl, .xsd, .js)1. xml display first & second level of detail of an element. (valid and working fine)2. xsl able to display the output that i want.3. xsd is firing well also (validate with my xml via xmlme.com/validator.aspx)4. in the browser displaying first & second level element,under second element shows a hyperlink which pass value of third level element unto .js5. this .js function suppose to pop out a window created in XMLDOM.6. poping out of window using template given was window.open('','',width=123, height=456, scrollbars=yes, noresize');7. problem now not sure if js can receive my value pass from xml docs and new window doesnt open up. :)

Link to comment
Share on other sites

You're missing a ' in the open() method, and there's no "noresize" (this is not frames you know). Should be:

window.open('', '', 'width=123, height=456, scrollbars=yes, resizable=no');

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...