471,337 Members | 1,319 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Xml namespace

Hello!

What is the reason for having xml namespace ?
I know the reason for using namespace in C# but I can't see any similarities
to Xml.

Can you just give a simple example on a Xml document where namespace will
solve the problem.

//Tony
Aug 14 '08 #1
3 1667
Tony Johansson <jo*****************@telia.comwrote:
What is the reason for having xml namespace ?
I know the reason for using namespace in C# but I can't see any similarities
to Xml.

Can you just give a simple example on a Xml document where namespace will
solve the problem.
You want to refer to elements in two different schemas, and both
elements are called "Foo". Namespaces allow you to differentiate.

In other words, it really is the same reason for having them in C#.
Admittedly they're a bit more of a pain in XML...

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Aug 14 '08 #2
It allows you to disambiguate between elements from different sources.
Perhaps more importantly, it allows you to write a compliant xml
document for cases when there is an expectation of namespaces ;-p

But as an example of the first, consider xslt; this uses a namespace
(commonly given the "xsl" alias) to indicate the xsl control statements
from output markup - i.e.

<xsl:choose>...</xsl:choose>

is a control statement (comparable to "switch"), where-as

<choose>...</choose>

(or other namespaces) is markup to be directed to the output stream.
Similarly, consider the <asp:Whatever>...</asp:Whateverin ASP.NET.

Marc
Aug 14 '08 #3
On Aug 14, 11:45*am, "Tony Johansson" <johansson.anders...@telia.com>
wrote:
Hello!

What is the reason for having xml namespace ?
I know the reason for using namespace in C# but I can't see any similarities
to Xml.

Can you just give a simple example on a Xml document where namespace will
solve the problem.
An example would be W3C XHTML+MathML+SVG profile (http://www.w3.org/TR/
XHTMLplusMathMLplusSVG/), which allows to use all three languages in a
single document, to represent formatted text, vector graphics, and
formulas. Sample XML using that profile looks like this - note the use
of namespaces used to separate the languages:

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>XHTML as the host language</title>
</head>
<body>
... XHTML content ...
<math xmlns="http://www.w3.org/1998/Math/MathML">
... MathML content ...
</math>
... XHTML content ...
<svg:svg version="1.1"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
... SVG content ...
<svg:switch>
<svg:foreignObject ...>
<p>
... XHTML content ...
<math xmlns="http://www.w3.org/1998/Math/MathML">
... MathML content ...
</math>
... XHTML content ...
</p>
</svg:foreignObject>
</svg:switch>
</svg:svg>
</body>
</html>
Aug 14 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by John L. Clark | last post: by
3 posts views Thread by Mike Dickens | last post: by
6 posts views Thread by Don Wash | last post: by
2 posts views Thread by puzzlecracker | last post: by
2 posts views Thread by Tony Johansson | last post: by
7 posts views Thread by Kevin Newman | last post: by
14 posts views Thread by Tiraman | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.