xmlbeans.jar newbie question

M

mlynch147

Hi

Im trying to write some code that takes an xml string as an input
parameter and from this string create an XML Object, and then using
the attributes of this object, use them to populate one of my
classes... I though it would work something like this....


public static void stringToXML(String xmlString) {

XmlObject xmlObj = XmlObject.Factory.newInstance();

try {
System.out.println("trying to parse xmlObj");
xmlObj = XmlObject.Factory.parse(xmlString);

myClass.setColour(xmlObj.getAttribute("Colour"));
myClass.setSpeed(xmlObj.getAttribute("Speed"));
etc...

But this doesnt seem to work.... can someone offer a bit of help to a
newbie please?

thanks
marty
 
J

Joe Kesselman

I don't know what "XmlObject" is. The usual object-based representation
of XML is the W3C's Document Object Model (DOM).

However, assuming that XmlObject is at least vaguely similar to the
DOM... to get the attributes of a given element, you have to ask that
specific element's object. I don't see any indication in your sketch
that you're actually navigating the document tree to the proper point to
retrieve that; it looks as if you're asking the root note, which has no
attributes.

You may want to look at a DOM tutorial. Many exist on the web, but my
standard recommendation is to start with the resources at
http://www.ibm.com/xml.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top