Reputation: 73
I am creating a KML document in Java. Inside of it i have to add many similar elements, resulting in the need to add a function, where I can pass needed arguments.
The problem is that when I try to add a part of the document into the main document it shows error, or creates malformed document. Here's a code snippet:
Element style = doc.createElement("Style");
style.setAttribute("id", "green");
dnode.appendChild(style);
Element polyStyle = doc.createElement("PolyStyle");
style.appendChild(polyStyle);
Element color = doc.createElement("color");
color.appendChild(doc.createTextNode("5014F064"));
polyStyle.appendChild(color);
Element iconStyle = doc.createElement("IconStyle");
style.appendChild(iconStyle);
color = doc.createElement("color");
color.appendChild(doc.createTextNode("5014F064"));
iconStyle.appendChild(color);
Element "dnode" is a Document element inside xml. I want to try something like this:
doc.appendChild(addFeatureStyle("red", "501400FA"));
Called three times with different parameters but have no idea how to include it. I want to add function written above, calling the code snippet.
Should the function "addFeatureStyle" return element, or a string, or something else?
Upvotes: 0
Views: 201
Reputation: 692033
I'm not sure I understand your question, but I'll try to answer:
Should the function "addFeatureStyle" return element, or a string, or something else?
You're calling the method appendChild()
with the value returned by addFeatureStyle("red", "501400FA")
as argument.
The documentation of appendChild() shows that it takes a Node as argument. So the return type of addFeatureStyle()
can't be a String: String doesn't implement the Node interface. The return type of addFeatureStyle()
must be Node
, or a class implementing Node
, or an interface extending Node
.
Upvotes: 1