W3C home > Mailing lists > Public > www-dom@w3.org > January to March 2001

Re: Problem getting attributes from a node

From: Eric Lawson <ericl@isogen.com>
Date: Fri, 09 Feb 2001 15:56:24 -0600
Message-ID: <3A846788.E1C59F71@isogen.com>
To: Lothar Behrens <lothar.behrens@okay.net>
CC: www-dom@w3.org
Perhaps a static_cast (or dynamic_cast) is necessary for converting a DOM_Node to a DOM_Attr.

DOM_Attr a_node = static_cast<DOM_Attr>attributeMap.getNamedItem(DOMString(name));

    Eric Lawson
    Isogen International

Lothar Behrens wrote:

> Hello,
>
> I am relatively new to the DOM/XML programming area. This is my first
> problem, by wich I will ask here.
>
> At first I put here a sample of the code for my problem (C++):
>
> DOM_NamedNodeMap attributeMap = node.getAttributes();
>
> char name[100] = "myattr";
>
> if (attributeMap == NULL) {
> CL_LOG("Error: This node is not of type ELEMENT");
>
> return ERR_UNSPECIFIED;
> }
>
> /**
> * The next line results in an error of the MSC 6.0 compiler like
> * this:
> Q:\DEVELOP\PROJECTS\CPP\BaseDevelopment\lbXMLConfig\lbDOMConfig\lbDOMC onfig.cpp(872) : error C2440: 'type cast' : cannot convert from 'class DOM_Node' to 'class DOM_Attr' No constructor could take the source type, or constructor overload resolution was ambiguous
> */
>
> DOM_Attr a_node = (DOM_Attr) attributeMap.getNamedItem(DOMString(name));
>
> if (a_node == NULL) {
> CL_LOG("Error: Attribute not found");
>
> return ERR_UNSPECIFIED;
> }
>
> How must I understand the attributes from the function
> getNamedItem(...) ?
>
> Is my found node really not of type DOM_Attr ?
>
> Why is there an interface for DOM_Attr but an expected result
> of this type could not be type cast to it ?
>
> What am I doing wrong ?
>
> Thanks
>
> Lothar
>
> -------------------------------------------------------- Lothar Behrens | Company: LotharB@powwowwater.de Borsteler Bogen 4 | C++ is the future, LINUX too :-) 22453 Hamburg | have a look at www.wxWindows.org
Received on Friday, 9 February 2001 17:00:53 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:48 GMT