开发者

Set up my own XML namespace?

How can I setup my 开发者_StackOverflow中文版own XML namespace?


Just define a namespace in the root tag (or wherever you need the namespace). Example:

<root xmlns:ns="some_identifier">

ns and the identifier can be (nearly) anything. See this quote:

What Do Namespace Names Point At?

One of the confusing things about all this is that namespace names are URLs; it's easy to assume that since they're Web addresses, they must be the address of something. They're not; these are URLs, but the namespace draft doesn't care what (if anything) they point at. Think about the example of the XML.com programmer looking for book titles; that works fine without the namespace name pointing at anything.

The reason that the W3C decided to use URLs as namespace names is that they contain domain names (e.g. www.xml.com), which work globally across the Internet.

The Wikipedia article is also quite informative.

I hope you know that you need namespaces just for distinguishing tags with the same name.


Like this:

<?xml version="1.0" encoding="UTF-8"?>
<someTag xmlns="your_very_own_xmlns"/>

To be serious: namespaces should be unique within a world, that's why they typically form the URI. But this is not a necessity. It is great if you own a domain and use it as a namespace, but you don't have. Of course you will run into trouble if someone else uses the same namespaces that is not unique. Using owned domain names guarantees that it will never happen.


You can define custom XML schema (with xml namespace) in XSD.

http://www.w3schools.com/Schema/schema_howto.asp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜