timothy ma and constance lee (
[email protected]) wrote:
: i have an xml file like
: <node type="Service" key="1">
: <value>Title</value>
: </node>
: <node type="Service" key="2">
: <value>CA</value>
: </node>
: Can java parse through the xml file to create an object like
: VO.getNodeType
: VO.getKey
: VO.getValue
two ways come to mind
-1-
parse the xml using a dom parser (java has a "few" of these available)
create a class that uses the dom parser to load the document into memory.
each access method in your class, e.g. getNodeType, is simply a front end
for the set of standard dom calls that return the desired information.
-2-
create a VO class that has the necessary new/get/set methods to create a
vo object
parse the xml using a sax parser (java has a "few" of these available),
and provide a sax content handler that does the following
a. creates a VO object when a <node > tag is found (current_VO = new VO)
b. uses the appropriate VO set methods to define the contents of the vo
object as each bit of information is available.
current_VO->setValue(-value-data-returned-by-sax-)
-3-
I bet there are prepackaged ways to do this, so I'm interested to hear
what other suggestions are made.