Why are URLs in XML namespaces?

When you ask why a standard is the way it is, there are two possible interpretations of your question: (a) what are the perceived benefits of the design choice that was made, and (b) what was the historical sequence of events that led to this design being adopted over other designs. Clearly, using HTTP-like URIs … Read more

How to Select XML Nodes with XML Namespaces from an XmlDocument?

You have to declare the dc namespace prefix using an XmlNamespaceManager before you can use it in XPath expressions: XmlDocument rssDoc = new XmlDocument(); rssDoc.Load(rssStream); XmlNamespaceManager nsmgr = new XmlNamespaceManager(rssDoc.NameTable); nsmgr.AddNamespace(“dc”, “http://purl.org/dc/elements/1.1/”); XmlNodeList rssItems = rssDoc.SelectNodes(“rss/channel/item”); for (int i = 0; i < 5; i++) { XmlNode rssDetail = rssItems[i].SelectSingleNode(“dc:creator”, nsmgr); if (rssDetail != null) … Read more

Why this line xmlns:android=”http://schemas.android.com/apk/res/android” must be the first in the layout xml file?

In XML, xmlns declares a Namespace. In fact, when you do: <LinearLayout android:id> </LinearLayout> Instead of calling android:id, the xml will use http://schemas.android.com/apk/res/android:id to be unique. Generally this page doesn’t exist (it’s a URI, not a URL), but sometimes it is a URL that explains the used namespace. The namespace has pretty much the same … Read more

XML Namespaces and Unprefixed Attributes

The normal interpretation used by XPath and other specs is that an unprefixed attribute is in no namespace. There are language lawyers who will insist that the namespaces spec doesn’t say that. It says that an unprefixed attribute is in whatever namespace the designer of the vocabulary says it is in. But this interpretation isn’t … Read more

How to serialize an object to XML without getting xmlns=”…”?

Ahh… nevermind. It’s always the search after the question is posed that yields the answer. My object that is being serialized is obj and has already been defined. Adding an XMLSerializerNamespace with a single empty namespace to the collection does the trick. In VB like this: Dim xs As New XmlSerializer(GetType(cEmploymentDetail)) Dim ns As New … Read more

Xml Namespace breaking my xpath!

I also have the following xPath: /List/Fields/Field When I remove the xmlns from my XML the xPath works fine. When it’s in there my xPath finds nothing If you cannot register a namespace binding and cannot use (assuming the registered prefix is “x”): /x:List/x:Fields/x:Field then there is another way: /*[name()=’List’]/*[name()=’Fields’]/*[name()=’Field’]

PHP namespace simplexml problems

Usually, people use children(). $rss = simplexml_load_string( ‘<?xml version=”1.0″ encoding=”utf-8″?> <rss version=”2.0″ xmlns:moshtix=”http://www.moshtix.com.au”> <channel> <link>qweqwe</link> <moshtix:genre>asdasd</moshtix:genre> </channel> </rss>’ ); foreach ($rss->channel as $channel) { echo ‘link: ‘, $channel->link, “\n”; echo ‘genre: ‘, $channel->children(‘moshtix’, true)->genre, “\n”; }