Jump to content

NameSpace


frozentree

Recommended Posts

hi, i`m very new to XML n i just finish with xml namespace tutorial.. i dint read the Xsl or xslt yet... i have make an experiment / research or test here.

<power>  <g:unit xmlns:g="http://www.omg.com">	 <g:sea>battleship</g:sea>	 <g:air>stealth bomber</g:air>  </g:unit></power>

this works! but.. when i add some more..

<power>  <g:unit xmlns:g="http://www.omg.com">	 <g:sea>battleship</g:sea>	<e:land xmlns:e="http://www.bom.com">	   <e:grass>soldier</e:grass>	   <e:platoo>flame gas</e:platoo>	 </e:land>	 <g:air>stealth bomber</g:air>  </g:unit></power>

its not working!!! what is happening? somebody give me some help please? tips may help too! thanks !!

Link to comment
Share on other sites

Namespaces using prefixes can only be declared in the root element. Infact, I'm wondering how the first example worked, as it declares a prefix in the child of a root node.So, to declare multiple prefixes, you'll use the root element, like this:

<power xmlns:g="http://www.omg.com" xmlns:e="http://www.bom.com">  <g:unit>	 <g:sea>battleship</g:sea>	<e:land>	   <e:grass>soldier</e:grass>	   <e:platoo>flame gas</e:platoo>	 </e:land>	 <g:air>stealth bomber</g:air>  </g:unit></power>

Your particular example may also use non-prefixed namespaces like this:

<power>  <unit xmlns="http://www.omg.com">	 <sea>battleship</sea>	<land xmlns="http://www.bom.com">	   <grass>soldier</grass>	   <platoo>flame gas</platoo>	 </land>	 <air>stealth bomber</air>  </unit></power>

Non-prefixed namespaces apply the namespace on the element they are applied on and all descendant nodes that don't use another namespace.

Link to comment
Share on other sites

What exactly do you mean by "not working"? The source tree is present when this document is opened and there is no error, meaning the document is well formed XML. What is it that is not working with you?

Link to comment
Share on other sites

i try to implement yr hints but still the same problem.. well that info u gave me is for file.xml .. for fileone.htm ,, i try to follow up with it.. this is fileone.htm

<html><body><xml id="coins" src="file.xml"></xml><table border="1" datasrc="#coins"><tr><td> <span datafld="g:sea"></span> </td><td> <span datafld="g:air"></span> </td></tr></table></body></html>

this is file.xml

<power xmlns:g="http://www.omg.com" xmlns:e="http://www.bom.com">  <g:unit>	 <g:sea>battleship</g:sea>	<e:land>	   <e:grass>soldier</e:grass>	   <e:platoo>flame gas</e:platoo>	 </e:land>	 <g:air>stealth bomber</g:air>  </g:unit></power>

is there anything wrong in this script? i wonder why too.

Link to comment
Share on other sites

Data Islands can't work with multydementional XMLs. They can only lock on one level and that's it. That is why your first example worked. Sea and Air are both on one level but when you added one level above, you're requring that both the inner and outer level are processed and that's something Data Islands can't do.There are so many reasons for not using them, so just don't use them. Any other method, just not this one, please.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...