You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by dara <da...@risaris.com> on 2005/06/27 18:34:13 UTC
list of attributes from a dom node
Hi all,
what is the best way to get and process a list of attributes from a
domNode/elementNode ?
i can find references for the SAX implementation, but not for DOM.
any pointers appreciated.
regards
dara
Re: list of attributes from a dom node
Posted by dara <da...@risaris.com>.
Axel Weiß wrote:
>dara wrote:
>
>
>>Hi all,
>>
>>what is the best way to get and process a list of attributes from a
>>domNode/elementNode ?
>>
>>i can find references for the SAX implementation, but not for DOM.
>>
>>any pointers appreciated.
>>
>>
>
>Hi dara,
>
>I usually do the following to traverse attributes:
>
>DOMNode *node; // the node we want to get the attrs of
> // this really should be a DOMElement
>
>DOMNamedNodeMap *map = node->getAttributes();
>int i, len = map ? map->getLength() : 0;
>for (i=0; i<len; ++i){
> DOMNode *attr = map->item(i);
> // here you have every attribute as a DOMNode,
> // and can read the attribute name / value
> // by attr->getNodeName() / attr->getNodeValue()
>}
>
>If you know the attribute name of interest a proiri, it is better to use
>the DOMElement methods getAttribute or getAttributeNode.
>
>I hope it helps,
> Axel
>
>
>
Hi Axel,
That will do nicely, i won't know the names of the attributes that are
there.
Go raibh míle maith agat,
Dara
Re: list of attributes from a dom node
Posted by Axel Weiß <aw...@informatik.hu-berlin.de>.
dara wrote:
> Hi all,
>
> what is the best way to get and process a list of attributes from a
> domNode/elementNode ?
>
> i can find references for the SAX implementation, but not for DOM.
>
> any pointers appreciated.
Hi dara,
I usually do the following to traverse attributes:
DOMNode *node; // the node we want to get the attrs of
// this really should be a DOMElement
DOMNamedNodeMap *map = node->getAttributes();
int i, len = map ? map->getLength() : 0;
for (i=0; i<len; ++i){
DOMNode *attr = map->item(i);
// here you have every attribute as a DOMNode,
// and can read the attribute name / value
// by attr->getNodeName() / attr->getNodeValue()
}
If you know the attribute name of interest a proiri, it is better to use
the DOMElement methods getAttribute or getAttributeNode.
I hope it helps,
Axel
--
Humboldt-Universität zu Berlin
Institut für Informatik
Signalverarbeitung und Mustererkennung
Dipl.-Inf. Axel Weiß
Rudower Chaussee 25
12489 Berlin-Adlershof
+49-30-2093-3050
** www.freesp.de **