Project

Profile

Help

namespaces of attributes

Added by Anonymous about 16 years ago

Legacy ID: #4771353 Legacy Poster: nico_inria (nico_inria)

Hi, It seems that is a well known and old problem : see http://xsd.stylusstudio.com/2000Nov/post01006.htm and I would like to have your opinions on it. I would like to create the simplest XML content : an element "root" with an attribute "rootAttribute", with the same namespace. Here is my code (I want to respect the JAXP specification) : //create the org.w3c.dom.Document object DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.newDocument(); //create the element root and its attribute rootAttribute Element root = document.createElementNS("http://test&quot;,&quot;root"); document.appendChild(root); Attr rootAttribute = document.createAttributeNS("http://test&quot;,&quot;attribute"); rootAttribute.setValue("value"); root.setAttributeNodeNS(rootAttribute); And here the Xml I get : <?xml version="1.0" encoding="UTF-8"?> <root xmlns="http://test" xmlns:NS1="http://test" NS1:attribute="value"/> !!?? So why do I have the same namespace declared twice with two different prefixes ?? Please tell me XML is not so complex.


Replies (3)

Please register to reply

RE: namespaces of attributes - Added by Anonymous about 16 years ago

Legacy ID: #4771464 Legacy Poster: Michael Kay (mhkay)

I don't quite see the relevance to Saxon? This seems to be a question about DOM processing. I'm no great fan of the DOM, and its handling of namespaces often seems fairly bizarre.

RE: namespaces of attributes - Added by Anonymous about 16 years ago

Legacy ID: #4775329 Legacy Poster: nico_inria (nico_inria)

You are right, it is not a problem with Saxon. Both serializers of Saxon or Xerces would give the same result. In my opinion, it is a problem with the DOM Level 3 specification itself, and I think that should be modified if the W3C really wants that we use namespaces in our XML. And if we don't, that will create lots of problems in the future, when we will try to combine XML from different sources. Are you involved in the W3C work ?

RE: namespaces of attributes - Added by Anonymous about 16 years ago

Legacy ID: #4775345 Legacy Poster: Michael Kay (mhkay)

I haven't been involved with the DOM work, and in fact I don't think W3C is doing any more work on DOM. In my view DOM has become a monster and it's too late to fix it. My advice is to use one of the alternatives, such as XOM.

    (1-3/3)

    Please register to reply