简体   繁体   中英

Fetch value of a node's attribute in XML

I have an XML document, a snippet of which is below:

<item name="entryDataItem" type="dataView" caption="__entry_data_item" id="208" formItem="selectbox"> 
<properties>
  <property name="caption" value="Task Type"/>
  <property name="name" value="task_type"/>
  </properties>
</item>
<item name="entryDataItem" type="dataView" caption="__entry_data_item"  id="211" formItem="text">
<properties>
  <property name="caption" value="Time Spent (Min)"/>
  <property name="name" value="time_spent_min"/>
  </properties>
</item>  

etc.

There are other "properties" as well. The value of "task_type" as well as all other properties are stored in database. When I iterate through the document, all the properties are fetched and a document is prepared with "caption" and "value" from the XML. The problem is , all the "properties" are printed. But I want contents of the document to be based on the "task_type"; say when the task_type value is TESTING", then only task_type "ESTIMATION" would be printed and nothing else.


I understand I have to put a check just before where the document is being prepared.
My question is: How do I put the condition when I only have "task_type" in the XML and not a value(eg."TESTING") directly within the XML document?


My code is a simple JAVA code.
Any help as to how this can be achived is much appreciated.


In my opinion, XPath is the bee's knees when it comes to going after specific items in a XML document. This article might be of some use if it's something you want to persue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM