Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of XSD files?

Tags:

xml

xsd

Since we can query on the XML file from C# (.NET), why do we need an XSD file? I know it is metadata file of particular XML file. We can specify the relationships in XSD, but what is its functioning then?

XML

<?xml version="1.0" encoding="utf-8" ?> <Root>   <Customers>     <Customer CustomerID="GREAL">       <CompanyName>Great Lakes Food Market</CompanyName>       <ContactName>Howard Snyder</ContactName>       <ContactTitle>Marketing Manager</ContactTitle>       <Phone>(503) 555-7555</Phone>       <FullAddress>         <Address>2732 Baker Blvd.</Address>         <City>Eugene</City>         <Region>OR</Region>         <PostalCode>97403</PostalCode>         <Country>USA</Country>       </FullAddress>     </Customer>   </Customers>   <Orders>     <Order>       <CustomerID>GREAL</CustomerID>       <EmployeeID>6</EmployeeID>       <OrderDate>1997-05-06T00:00:00</OrderDate>       <RequiredDate>1997-05-20T00:00:00</RequiredDate>       <ShipInfo ShippedDate="1997-05-09T00:00:00">         <ShipVia>2</ShipVia>         <Freight>3.35</Freight>         <ShipName>Great Lakes Food Market</ShipName>         <ShipAddress>2732 Baker Blvd.</ShipAddress>         <ShipCity>Eugene</ShipCity>         <ShipRegion>OR</ShipRegion>         <ShipPostalCode>97403</ShipPostalCode>         <ShipCountry>USA</ShipCountry>       </ShipInfo>     </Order>     <Order>       <CustomerID>GREAL</CustomerID>       <EmployeeID>8</EmployeeID>       <OrderDate>1997-07-04T00:00:00</OrderDate>       <RequiredDate>1997-08-01T00:00:00</RequiredDate>       <ShipInfo ShippedDate="1997-07-14T00:00:00">         <ShipVia>2</ShipVia>         <Freight>4.42</Freight>         <ShipName>Great Lakes Food Market</ShipName>         <ShipAddress>2732 Baker Blvd.</ShipAddress>         <ShipCity>Eugene</ShipCity>         <ShipRegion>OR</ShipRegion>         <ShipPostalCode>97403</ShipPostalCode>         <ShipCountry>USA</ShipCountry>       </ShipInfo>     </Order>   </Orders> </Root> 

I want to get data from the Order elements according to a provided CustomerID.

Also: What is the purpose of giving the relationships in XSD?

like image 976
Red Swan Avatar asked Aug 04 '10 08:08

Red Swan


People also ask

What is the use of XSD file?

The XML Schema definition language (XSD) enables you to define the structure and data types for XML documents. An XML Schema defines the elements, attributes, and data types that conform to the World Wide Web Consortium (W3C) XML Schema Part 1: Structures Recommendation for the XML Schema Definition Language.

Do I need an XSD file?

XSDs constrain the vocabulary and structure of XML documents. Without an XSD, an XML document need only follow the rules for being well-formed as given in the W3C XML Recommendation.

Why XSD is used in XML?

XML Schema is commonly known as XML Schema Definition (XSD). It is used to describe and validate the structure and the content of XML data. XML schema defines the elements, attributes and data types. Schema element supports Namespaces.

What are the advantages of XSD?

Advantages of XSD over DTDYou can derive new elements from the existing elements. DTD is not extensible. XSD is defined in XML. It does not require intermediate processing by a parser.


1 Answers

XSD files are used to validate that XML files conform to a certain format.

In that respect they are similar to DTDs that existed before them.

The main difference between XSD and DTD is that XSD is written in XML and is considered easier to read and understand.

like image 185
Oded Avatar answered Sep 20 '22 21:09

Oded