Friday, 9 January 2015

find if a tag exists by name in XMl using Java Dom



how can i check if a specific child dose not exist in XML using Java Dom in the following sample: I am looking for all userFiled occurances and in the first part, there is non. So I want to say if there is no tag "userField" do something.



<element class="AufOrgKombination" hash="AOK_1416092142370_76">
<field name="layer">4</field>
<field name="name">Function organisation unit combination 1</field>
<field name="description"/>
</element>
<element class="AufOrgKombination" hash="AOK_1417643334024_77">
<field name="layer">4</field>
<field name="name">Function organisation unit combination 1</field>
<field name="description"/>
<userField hash="USERFIELD_1415779871581_0">3.0</userField>
<userField hash="USERFIELD_1415779871581_0">N.A.</userField>
</element>


something like: NodeList NodeuserField = element.getElementsByTagName("userField"); Element line;



for (int j = 0, l = NodeuserField.getLength(); j < l; j++) {
line = (Element) NodeuserField.item(j);
for (Entry<String, String> userFieldUserDef : map_userField
.entrySet()) {
if (element.getElementsByTagName("hash") == null) {

//Do Something

}

No comments:

Post a Comment