From: John B. <jx...@ga...> - 2000-11-04 18:59:23
|
> > > Hi All, > > I've been looking the API document for a while. I still couldn't know > how to retrieve the value of each attribute. > > Eg. how can we get 1.3 value out of this node > <CURRENTREVISION HEAD = "1.3"> ..............</CURRENTREVISION> > > In the psedocode: currev->getAttribut("HEAD") > > But after I check out the API, it doesn't have this > getAttribute(String) method function. It has getAttri(), which returns > DOM_NamedNodeMap. I don't what I can do with DOM_NamedNodeMap. In this > class, it doesn't say anything about the atrribute data type ,value Hi, Jake. getAttribute() is a method of the DOM_Element class. The inheritance hierarchy may be throwing you off; DOM_Element inherits from DOM_Node, so you have all methods from both classes to call for a DOM_Element. getAttribute() returns a DOMString,which appears to be overloaded to behave almost like a regular string. (But consult the docs to be sure). All of the methods on Xerces objects in that pseudocode are defined somewhere in the documentation. I got most of them out of DOMPrint.cpp. > To J. David, > > To get data for head_text > To get head_text, do we need to get the first child? > head_text = currev->getFirstChild->getData > I couldn't find getData member function in DOM_Node also. Yes, you need to get the first child of the <CURRENTREVISION/> element. Look at the following code from the hacked-up DOMPrint.cpp I sent: DOM_Element catElem = doc.createElement("category"); ... DOM_Text catDataVal = doc.createTextNode("XML Parsing Tools"); catElem.appendChild(catDataVal); An element called <category/> is created, and then the text "XML Parsing Tools" is added into it, so that it looks like this: <category>XML Parsing Tools</category> In Xerces terms, the text node containing the text of the element is the first child node of the category element. This is exactly the situation we face with the head_text in <CURRENTREVISION/>. The text is a DOM_Text, which inherits from DOM_CharacterData. getData() is an object method of the DOM_CharacterData class. Thanks. <jdb status="here if you need me"> :) </jdb> |