Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a ZUI application using the packages from Piccolo2D.

The way piccolo2D works is that you create nodes, which are then displayed within the panel. You can add additional nodes to the panel or add it to the node you have just created and so on to make a hierarchy structure.

Each node has several properties and normally you can hard-code them in when you create the node. What I want to do however is store these property values in an XML file, parse these values in and then create the node with these values.

I got reading in the values from the XML file using the SAX parser, and this then prints out the values within the console, that isn't the problem. The problem is actually getting the values read from the XML file into the properties of the node.

So for example when you create a node, you do so by adding this code (filling in the values):

Java
PNode node1 = PPath.createRoundRectangle(x, y, width, height, arc, arc);


However I want to get the values read in from the SAX parser and insert the property values for the node, and I am having problems doing this.

Can anyone help me?
Posted
Comments
TorstenH. 3-Nov-11 3:05am    
What are you trying to do? How should the data, that you want to read be created?
IMHO it doesn't make much difference from where you get your data - you would just have to parse them.

1 solution

Hmm... Why do you not try something like (simplified):

int x_fromXml = getAsInt(xmlElement_x);
int y_fromXml = getAsInt(xmlElement_y);

int width_fromXml = getAsInt(xmlElement_width);
int heigth_fromXml = getAsInt(xmlElement_hight);

Arc arc1_fromXml = getAsArc(xmlElement_arc1);
Arc arc2_fromXml = getAsArc(xmlElement_arc2);

PNode node1 = PPath.createRoundRectangle(x_fromXml , y_fromXml , width_fromXml , heigth_fromXml , arc1_fromXml , arc2_fromXml );


With getAsInt() and getAsArc() parses the provided XML-Element and returns the appropriate data type?

If that is not the Solution, then please state your problem again, since you said that you could parse and print the stuff from the XML, but not put it into your provided line of code.

If you don't know how to parse a String (returned from the XML) into int etc, then here it comes:

Integer myInt = Integer.parse(stringFromXml);


Similar for Dounble, Float or Long. Additionally you might want to catch a NumberFormatException in case the Parsing failed.

Cheers, Arndt
 
Share this answer
 
Comments
Willtwinny 1-Jan-12 17:54pm    
I managed to get it working in the end, and when I logged in and noticed this answer and it is very similar to what I got so I accepted it as the best answer. Hopefully other people will find it helpful :-) Thank-You for helping me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900