Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6767847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:00:00+00:00 2026-05-26T15:00:00+00:00

I am trying to parse the following XML: <?xml version=1.0 encoding=UTF-8?> <!– _tag –>

  • 0

I am trying to parse the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<!-- _tag -->
<tag value="0" actions_tagged="0" name="adjust temperature">
  <link type="application/xml" rel="list" href="/api/v1/tags.xml"/>
  <link type="application/xml" rel="self" href="/api/v1/tags/adjust%20temperature.xml"/>
  <actions>
    <action id="105">
      <link type="application/xml" rel="tagged_action" href="/api/v1/actions/105.xml"/>
      <short_name>Set thermostat to 68F in the winter and 74F in the summer</short_name>
    </action>
    <action id="106">
      <link type="application/xml" rel="tagged_action" href="/api/v1/actions/106.xml"/>
      <short_name>Close windows and blinds</short_name>
    </action>
  </actions>
</tag>

I would like to capture each “action id” and each “short name”. I’m able to capture the short name with the following code. But, how do you obtain the corresponding action id?

String action = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Actions myActions  = new Actions();
InputSource inStream = new InputSource();
inStream.setCharacterStream(new StringReader(xml));

Document doc = db.parse(inStream);
NodeList nodeList = doc.getElementsByTagName("action");

for (int s = 0; s < nodeList.getLength(); s++) {
  Node fstNode = nodeList.item(s);
  if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
    Element fstElmnt = (Element) fstNode;

    NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("short_name");
    Element lstNmElmnt = (Element) lstNmElmntLst.item(0);
    NodeList lstNm = lstNmElmnt.getChildNodes();
    String currentAction = ((Node) lstNm.item(0)).getNodeValue();
    if(currentAction != null) {
      myActions.setShort_name(currentAction);
    }

    lstNmElmntLst = fstElmnt.getElementsByTagName("action id"); 
    // this didn't work - nor did 'id'
    lstNmElmnt = (Element) lstNmElmntLst.item(0);
    lstNm = lstNmElmnt.getChildNodes();
    currentAction = ((Node) lstNm.item(0)).getNodeValue();
    if(currentAction != null) {
      myActions.setDescription(currentAction);
    }
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:00:01+00:00Added an answer on May 26, 2026 at 3:00 pm

    The id value is an attribute on the action tag, so once you’re at the proper node, you’ll want to get the id from it by something like

    String idValue = fstElmnt.getAttribute("id"); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to parse the following XML with javascript: <?xml version='1.0' encoding='UTF-8'?> <ResultSet>
guys Following is the xml which i am trying to parse <?xml version=1.0 encoding=UTF-8?><Categories><category
I am tring to parse the following file: <?xml version=1.0 encoding=UTF-8 ?> <printDrivers> <printDriver
I am trying to parse a dom element. Element element: <?xml version=1.0 encoding=UTF-8?> <feed
Hi Guys I am having following type of XML to parse. <?xml version=1.0 encoding=utf-8
Something's screwy here. I'm trying to parse this XSL file: <?xml version=1.0 encoding=utf-8?> <xsl:stylesheet
I have the following xml file: <?xml version=1.0 encoding=UTF-8?> <c1> <c2 id=0001 n=CM urlget=/at/CsM
i have the following xslt sheet: <?xml version=1.0 encoding=UTF-8 ?> <xsl:stylesheet xmlns:xsl=http://www.w3.org/1999/XSL/Transform version=1.0> <xsl:variable
I have the following xml snippet: <?xml version=1.0 encoding=UTF-8 ?> <!DOCTYPE sqlMap PUBLIC -//ibatis.apache.org//DTD
I have an XML file of the following structure: <?xml version=1.0 encoding=utf-8?> <root> <ArrayOfLocationDTO

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.