Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you link XML to a XSD?

Tags:

Been wondering, just as we use the -declaration to bind XML to a DTD, how do we do it with XSD?

MSDN sample:

<?xml version="1.0"?> <Product ProductID="123"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:noNamespaceSchemaLocation="Product.xsd">     <ProductName>Rugby jersey</ProductName> </Product>  

is it the xsi:NoNamespaceSchemaLocation that does the trick? Or is this just another namespace?

[EDIT] And is the

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

..line just for giving us a unique XML namespace, or does it also provide information on where the schema can be located?

like image 776
cwap Avatar asked Apr 11 '09 20:04

cwap


People also ask

How connect XML to XSD?

Reference the XSD schema in the XML document using XML schema instance attributes such as either xsi:schemaLocation or xsi:noNamespaceSchemaLocation. Add the XSD schema file to a schema cache and then connect that cache to the DOM document or SAX reader, prior to loading or parsing the XML document.

How do you reference XML schema in XML?

A XML Schema can be referenced from an XML document by defining the schemaLocation and noNamespaceSchemaLocation attributes. The 'schemaLocation' attribute is used to reference XML Schema(s) that are defined in a target-namespace.

Can XML convert to XSD?

To create an XML file from an XSD file: Right-click the XML Documents folder in your data development project, and select New > XML. The New XML File wizard opens. Select the XMLSchema project in the parent folder field, type customer.


1 Answers

Try schemaLocation.

<?xml version="1.0"?>  <note xmlns="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> 

noNamespaceSchemaLocation is different. Note that both are indeed only "hints" in theory, to a consumer of an XML document. I've never run into an xml processor that did not follow them; after all, it's a W3C recommendation. see http://www.w3.org/TR/xmlschema-1/

But indeed, it could go wrong, as here, but then again, it's considered a bug for a reason.

To go short : I just trust it, with no harm so far :-)

I don't think any half-decent xml processor can ignore this 'hint' these days.

The urls are always for uniqueness, but in some cases some info will be provided under the URL.

like image 153
Peter Avatar answered Oct 11 '22 16:10

Peter