Jump to content

Quite new at this XML stuff


Guest FirefoxRocks

Recommended Posts

Guest FirefoxRocks

From what I learn in the XML tutorial, it should be this, right?

<fr:root xmlns:fr="http://example.net"><fr:element1>some data</fr:element1><fr:element2>some more data</fr:element2></fr:root>

is the same as:

<fr:root xmlns:fr="http://example.net"><element1>some data</element1><element2>some more data</element2></fr:root>

Is that right? Or do I have to declare the name space in each of the child elements?

Link to comment
Share on other sites

You are only "declaring" the namespace once. You're then only "reffering to" or otherwise "placing certain elements in" or simply said "use" that namespace.You declare a namespace with

xmlns:fr="http://example.net"

and you use that namespace by prefixing all elements in it with the prefix you specified when declaring it.If you do not specify a prefix, then the element you declare it on (if it is without a prefix) and all of it's descendants without a prefix will be in that namespace.So,

<fr:root xmlns:fr="http://example.net"><fr:element1>some data</fr:element1><fr:element2>some more data</fr:element2></fr:root>

is equivalent to

<root xmlns="http://example.net"><element1>some data</element1><element2>some more data</element2></root>

While

<fr:root xmlns:fr="http://example.net"><element1>some data</element1><element2>some more data</element2></fr:root>

is equivalent to

<root xmlns="http://example.net" xmlns:fr=""><fr:element1>some data</fr:element1><fr:element2>some more data</fr:element2></root>

Link to comment
Share on other sites

Guest FirefoxRocks

So even if the parent/ancestor element refers to the namespace, the child elements don't inherit the name space?So are you saying that:

<fr:root xmlns:fr="http://example.net"><fr:element /></fr:root>

is not the same as:

<fr:root xmlns:fr="http://example.net"><element /></fr:root>

I seriously don't want to make this huge mistake creating an XML document and then change all of the element names.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...