Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of targetNamespace in XML

Tags:

xml

xsd

How is targetNamespace used in XML? An explanation with some real examples would be great.

like image 773
user845392 Avatar asked Oct 27 '25 00:10

user845392


2 Answers

Strictly speaking, targetNamespace doesn't belong to XML per se, but to XML Schema (which is, of course, itself XML). When you define a schema, you define a structure of XML nodes (mainly elements and attributes) that an XML instance (i.e. your "XML file") must conform to.

Usually (not necessarily), those XML nodes will reside in a namespace. This means that when the XML instance is validated against the schema, the nodes in the instance will have to reside in that namespace for the instance to be valid.

The schema's targetNamespace attribute simply defines which namespace that is.

like image 85
Dabbler Avatar answered Oct 29 '25 15:10

Dabbler


If you want a general overview of namespaces in XML, James Clark's explanation at http://www.jclark.com/xml/xmlns.htm is excellent.

"targetNamespace" is an attribute of an XML Schema Document. When you define an XSD schema, you have to write it in a modular way, with one or more XML Schema Documents for each namespace that you are defining. (Usually you will only be defining one namespace, but you may import schema documents for other namespaces if these are used in your vocabulary.) The targetNamespace of a schema document defines which namespace the element declarations (and other declarations and definitions) in that schema document belong to.

like image 29
Michael Kay Avatar answered Oct 29 '25 15:10

Michael Kay