How to create the following XML tag through DOM in Java
<tableCategory>
<item app_name="APPNAME1i" desc="BDESC1" lang="1ODDD"/>
</tableCategory>
In the above xml tag, I want to add one more item as follows-
<item app_name="APPNAME2" de开发者_高级运维sc="DESC2" lang="2ODDD"/>
So finally the XML tag will look like-
<tableCategory>
<item app_name="APPNAME1i" desc="BDESC1" lang="1ODDD"/>
<item app_name="APPNAME2" desc="DESC2" lang="2ODDD"/>
</tableCategory>
I am getting the tag -
Element paletteElement = (Element) doc.getElementsByTagName("tableCategory").item(0); //tag
But not getting the clue after that.
Assuming you are using javax.xml.parsers
, element.appendChild()
will do.
[edited]
In case, you are looking for how to create a new Element
, below is an example snippet
Element newElem = doc.createElement("item");
newElem.setAttribute(...);
...
...
elem.addChild(newElem);
Look at the Element.addContent() method
精彩评论