You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Michael Ludwig <mi...@gmx.de> on 2009/04/07 23:34:08 UTC

DOM: Are namespace declaration attributes real attributes?

Given the following input document:

    <Urmel a="1" b="2" xmlns="urn:x-U" xmlns:v="urn:x-V"/>

And the following code:

    static void showAttributes(Document doc) {
        Node docElm = doc.getDocumentElement();
        NamedNodeMap nodeMap = docElm.getAttributes();
        int len = nodeMap.getLength();
        for (int i = 0; i < len; i++) {
            Attr attr = (Attr) nodeMap.item(i);
            System.out.println(attr.getName() + " " + attr);
        }
    }

Four attributes are shown:

    a a="1"
    b b="2"
    xmlns xmlns="urn:x-U"
    xmlns:v xmlns:v="urn:x-V"

Do namespace declaration attributes count as real attributes in the DOM?

I noticed that contrary to Xerces, LibXML2 does not count namespace
declaration attributes among the real attributes.

Can I make the Xerces parser or the document not include them among the
attributes? (In the XPath Data Model, they're not attributes.)

Or do they filter out the xmlns: attributes by checking the prefix and
the namespace URI when building the XDM from the DOM?

Michael Ludwig

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: DOM: Are namespace declaration attributes real attributes?

Posted by Michael Ludwig <mi...@gmx.de>.
Michael Glavassevich schrieb am 08.04.2009 um 15:03:58 (-0400):
> Michael Ludwig <mi...@gmx.de> wrote on 04/08/2009 02:52:22 PM:

> > And I was wondering if Xerces had a DOM parser option to not enlist
> > namespace declaration attributes among the ordinary attributes as
> > in:
> >
> >   NamedNodeMap nodeMap = elm.getAttributes();
> >
> > If so, I haven't found it. Just asking because coming from LibXML2
> > (which I'm not saying is the Specification Incarnate), I'm not used
> > to finding namespace declaration attributes together with straight
> > attributes when using the DOM parser. So maybe there is some switch
> > controlling that behaviour in Xerces?
> 
> There is one but you need to be using the DOM Level 3 LSParser [1].
> Setting the "namespace-declarations" parameter to false on its
> DOMConfiguration [2] should do the trick.

Thanks! It works!

  String xmlFileName = "c:/dev/XML/urmel.xml";
  DOMImplementationRegistry registry =
    DOMImplementationRegistry.newInstance();
  DOMImplementationLS impl =
    (DOMImplementationLS) registry.getDOMImplementation("LS");
  LSParser parser =
    impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
  DOMConfiguration domConf = parser.getDomConfig();
  domConf.setParameter("namespace-declarations", false);
  Document doc = parser.parseURI(xmlFileName);

Michael Ludwig

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: DOM: Are namespace declaration attributes real attributes?

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Michael Ludwig <mi...@gmx.de> wrote on 04/08/2009 02:52:22 PM:

> keshlam@us.ibm.com schrieb am 07.04.2009 um 22:03:16 (-0400):
> > In the DOM, namespace declaration attributes are displayed as real
> > attributes -- but are in fact optional in many cases.
>
> Thanks keshlam, and Nathan, for answering.
>
> > See current version of the DOM spec for discussions of Namespace
> > Well-Formedness, Namespace Normalization, and normalization during
> > serialization.
>
> http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/namespaces-
> algorithms.html#normalizeDocumentAlgo
>
> I think this refers rather to the question of which namespace
> declaration attributes are required in order for a given document
> to be namespace-well-formed.
>
> > In the XPath data model, namespace declarations are not considered
> > attributes.
>
> Yes. And I was wondering if Xerces had a DOM parser option to not enlist
> namespace declaration attributes among the ordinary attributes as in:
>
>   NamedNodeMap nodeMap = elm.getAttributes();
>
> If so, I haven't found it. Just asking because coming from LibXML2
> (which I'm not saying is the Specification Incarnate), I'm not used
> to finding namespace declaration attributes together with straight
> attributes when using the DOM parser. So maybe there is some switch
> controlling that behaviour in Xerces?

There is one but you need to be using the DOM Level 3 LSParser [1]. Setting
the "namespace-declarations" parameter to false on its DOMConfiguration [2]
should do the trick.

> Michael Ludwig
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org

Thanks.

[1]
http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407/load-save.html#LS-LSParser
[2]
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#DOMConfiguration


Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Re: DOM: Are namespace declaration attributes real attributes?

Posted by Michael Ludwig <mi...@gmx.de>.
keshlam@us.ibm.com schrieb am 07.04.2009 um 22:03:16 (-0400):
> In the DOM, namespace declaration attributes are displayed as real
> attributes -- but are in fact optional in many cases.

Thanks keshlam, and Nathan, for answering.

> See current version of the DOM spec for discussions of Namespace
> Well-Formedness, Namespace Normalization, and normalization during
> serialization.

http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/namespaces-algorithms.html#normalizeDocumentAlgo

I think this refers rather to the question of which namespace
declaration attributes are required in order for a given document
to be namespace-well-formed.

> In the XPath data model, namespace declarations are not considered
> attributes.

Yes. And I was wondering if Xerces had a DOM parser option to not enlist
namespace declaration attributes among the ordinary attributes as in:

  NamedNodeMap nodeMap = elm.getAttributes();

If so, I haven't found it. Just asking because coming from LibXML2
(which I'm not saying is the Specification Incarnate), I'm not used
to finding namespace declaration attributes together with straight
attributes when using the DOM parser. So maybe there is some switch
controlling that behaviour in Xerces?

Michael Ludwig

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: DOM: Are namespace declaration attributes real attributes?

Posted by ke...@us.ibm.com.
In the DOM, namespace declaration attributes are displayed as real 
attributes -- but are in fact optional in many cases. See current version 
of the DOM spec for discussions of Namespace Well-Formedness, Namespace 
Normalization, and normalization during serialization.

In the XPath data model, namespace declarations are not considered 
attributes.

______________________________________
"... Three things see no end: A loop with exit code done wrong,
A semaphore untested, And the change that comes along. ..."
  -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish (
http://www.ovff.org/pegasus/songs/threes-rev-11.html)



Nathan Beyer <nb...@gmail.com> 
04/07/2009 05:59 PM
Please respond to
j-users@xerces.apache.org


To
"j-users@xerces.apache.org" <j-...@xerces.apache.org>
cc

Subject
Re: DOM: Are namespace declaration attributes real attributes?






Xmlns attributes are regular attributes. The only thing special about 
them is that they have an implicitly defined namespace.

-Nathan

Sent from my iPhone

On Apr 7, 2009, at 5:34 PM, Michael Ludwig <mi...@gmx.de> wrote:

> Given the following input document:
>
>    <Urmel a="1" b="2" xmlns="urn:x-U" xmlns:v="urn:x-V"/>
>
> And the following code:
>
>    static void showAttributes(Document doc) {
>        Node docElm = doc.getDocumentElement();
>        NamedNodeMap nodeMap = docElm.getAttributes();
>        int len = nodeMap.getLength();
>        for (int i = 0; i < len; i++) {
>            Attr attr = (Attr) nodeMap.item(i);
>            System.out.println(attr.getName() + " " + attr);
>        }
>    }
>
> Four attributes are shown:
>
>    a a="1"
>    b b="2"
>    xmlns xmlns="urn:x-U"
>    xmlns:v xmlns:v="urn:x-V"
>
> Do namespace declaration attributes count as real attributes in the 
> DOM?
>
> I noticed that contrary to Xerces, LibXML2 does not count namespace
> declaration attributes among the real attributes.
>
> Can I make the Xerces parser or the document not include them among 
> the
> attributes? (In the XPath Data Model, they're not attributes.)
>
> Or do they filter out the xmlns: attributes by checking the prefix and
> the namespace URI when building the XDM from the DOM?
>
> Michael Ludwig
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org



Re: DOM: Are namespace declaration attributes real attributes?

Posted by Nathan Beyer <nb...@gmail.com>.
Xmlns attributes are regular attributes. The only thing special about  
them is that they have an implicitly defined namespace.

-Nathan

Sent from my iPhone

On Apr 7, 2009, at 5:34 PM, Michael Ludwig <mi...@gmx.de> wrote:

> Given the following input document:
>
>    <Urmel a="1" b="2" xmlns="urn:x-U" xmlns:v="urn:x-V"/>
>
> And the following code:
>
>    static void showAttributes(Document doc) {
>        Node docElm = doc.getDocumentElement();
>        NamedNodeMap nodeMap = docElm.getAttributes();
>        int len = nodeMap.getLength();
>        for (int i = 0; i < len; i++) {
>            Attr attr = (Attr) nodeMap.item(i);
>            System.out.println(attr.getName() + " " + attr);
>        }
>    }
>
> Four attributes are shown:
>
>    a a="1"
>    b b="2"
>    xmlns xmlns="urn:x-U"
>    xmlns:v xmlns:v="urn:x-V"
>
> Do namespace declaration attributes count as real attributes in the  
> DOM?
>
> I noticed that contrary to Xerces, LibXML2 does not count namespace
> declaration attributes among the real attributes.
>
> Can I make the Xerces parser or the document not include them among  
> the
> attributes? (In the XPath Data Model, they're not attributes.)
>
> Or do they filter out the xmlns: attributes by checking the prefix and
> the namespace URI when building the XDM from the DOM?
>
> Michael Ludwig
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org