Tahlil
Tahlil

Reputation: 2731

xmlns format confusion

<linkbase xsi:schemaLocation="http://www.w3.org/1998/linkbase http://www.xbrl.org/2003/schema.xml" xmlns="http://www.noprefix.org/2003/linkbase" xmlns:xlink="http://www.w3.org/2005/xlink" xmlns:xsi="http://www.w3.org/1999/XMLSchema">
  <roleRef roleURI="http://www.greenserve.com/role/Commitgencies" xlink:href="Commitmentsngencies" xlink:type="simple" />
  </linkbase>

In this xml there is a xmlns attribute without followed by a : and a prefix name.

xmlns="http://www.noprefix.org/2003/linkbase"

but others have a colon and prefix after the xmlns. So when I try to parse this xml to get the roleref tags with the "descendants" function it doesn't show anything. But if I add a : and a prefix after that xmlns then it can parse properly. Why it acts like it can anyone explain? Thanks.

Upvotes: 0

Views: 1146

Answers (1)

jlmcdonald
jlmcdonald

Reputation: 13667

When you have an xmlns attribute without a colon and a prefix, this is the default namespace for the entire document ... so all unprefixed elements will be in that default namespace. This is not the same as not having namespace, however. Remember that the namespace is actually the URI, not the prefix ... the prefix is just a shortcut way of referring to this. So if you have an xml file like this:

<xml xmlns="http://example.org" xmlns:ex="http://example2.org">
<element1/>
<element2/>
<ex:element3>
</xml>

The elements that don't have the namespace prefix cannot just be addressed by element name alone, as they're still in the namespace http://example.org.

Now, as to how to parse it ... this all depends on your tool. If it's XSLT, in your XSLT file you can give that namespace a temporary prefix so as to address those elements. Every library in every programming language might have a different way to do it (as just one of many examples, lxml in python would address the default namespaced elements like this: {http://example.org}element1). You'll have to refer to whatever you're using to do the parsing for help on how to handle elements that are in the default namespace.

Upvotes: 1

Related Questions