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 7443995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:25:18+00:00 2026-05-29T11:25:18+00:00

I’ve got an app that consumes a .NET web service which returns an XML

  • 0

I’ve got an app that consumes a .NET web service which returns an XML string of data. I’m trying to read this XML and insert it into the local SQLite DB but I’m having some trouble. Here’s a sample of the xml:

<?xml version="1.0" encoding="utf-8" ?> 
<string xmlns="RemoteWebService"><OpenIssues> <Table> <IssueID>15351</IssueID>   <IssueSummary>Computer keeps crashing. This continues to be a problem</IssueSummary> <LocationName>West Side</LocationName> <Status>WIP</Status> <CustomerID>89755</CustomerID> <CustomerName>West Side Computers</CustomerName> <CustomerShortName>WSC</CustomerShortName> <Notes /> <STATUS1>Work In Progress</STATUS1> <SubmittedBy>WSC - Tom Johns</SubmittedBy> <EQ_Replaced>true</EQ_Replaced></Table> </OpenIssues></string> 

Using DOM, I’m trying to parse the results like so:

private void GetLatestData(String response) throws ParserConfigurationException, SAXException, IOException{

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(new InputSource(new StringReader(response)));

    //Normalize the document.
    doc.getDocumentElement().normalize();

    //Get Root Node.
    NodeList nodeList = doc.getElementsByTagName("Table");
    Node node = nodeList.item(0);

    //Get Child Nodes.
    for(int i = 0; i < node.getChildNodes().getLength(); i++){
        IssueInfo issue = new IssueInfo();
        Node tempNode = node.getChildNodes().item(i);

        if(tempNode.getNodeName().equalsIgnoreCase("IssueID")){
            issue.setIssueNumber(Long.parseLong(tempNode.getTextContent()));
        }

        if(tempNode.getNodeName().equalsIgnoreCase("IssueSummary")){
            issue.setIssueNumber(Long.parseLong(tempNode.getTextContent()));
        }               

        if(issue.getIssueNumber() > 0 && issue.getIssueSummary() != null){
            creator = new IssueInfoCreator(this, DBVersion);
            creator.open();
            creator.InsertIssue(issue.getIssueNumber(), DateFormat.getDateInstance().format(new Date()), issue.getIssueSummary());
            creator.close();
        }
    }
}

When I run it through the debugger, it gets “IssueID” just fine but how can I get it to pickup the next node “IssueSummary” right after that so I can insert the data at once? It seems like I need another loop somewhere, just not too sure where though.

  • 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-29T11:25:20+00:00Added an answer on May 29, 2026 at 11:25 am

    Finally found the resolution to this with the help of my coworker and some digging around. It should be noted that we changed the WebService that returned a string from DataSet.GetXml() to an XmlDocument.InnerXml. This removed the spaces in between the nodes and then we were able to move forward from there. Here’s the final code we used:

    public void GetLatestData(SoapPrimitive xml)throws ParserConfigurationException, SAXException, IOException{
        //get the factory
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    
        //Using factory get an instance of document builder
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc;
    
        //parse using builder to get DOM representation of the XML file
        InputSource is = new InputSource(new StringReader(xml.toString()));
        doc = db.parse(is);
    
       //Clear out Issues table first.
       creator = new IssueInfoCreator(this, DBVersion);
       creator.open();
       creator.ClearIssueTable();
       creator.close();
    
       NodeList nodes = doc.getElementsByTagName("Table");
    
       for(int i = 0; i < nodes.getLength(); i++) {
           IssueInfo issue = new IssueInfo();
    
           Element e = (Element)nodes.item(i);
    
           issue.setIssueNumber(Long.parseLong(XMLfunctions.getValue(e, "IssueID")));
           issue.setIssueSummary(XMLfunctions.getValue(e, "IssueSummary"));
           issue.setDateReceived(DateFormat.format("MM/dd/yyyy hh:mm:ss", System.currentTimeMillis()).toString());
    
           if(issue.getIssueNumber() > 0 && issue.getIssueSummary() != null){
               creator = new IssueInfoCreator(this, DBVersion);
               creator.open();
               creator.InsertIssue(issue.getIssueNumber(), issue.getDateReceived(), issue.getIssueSummary());
               creator.close();
           }
       }
    }
    

    And here is the getValue method of the XMLfuntions class:

    public static String getValue(Element item, String str) {       
        NodeList n = item.getElementsByTagName(str);        
        return XMLfunctions.getElementValue(n.item(0));
    }
    
     public final static String getElementValue( Node elem ) {
         Node kid;
         if( elem != null){
             if (elem.hasChildNodes()){
                 for( kid = elem.getFirstChild(); kid != null; kid = kid.getNextSibling() ){
                     if( kid.getNodeType() == Node.TEXT_NODE  ){
                         return kid.getNodeValue();
                     }
                 }
             }
         }
         return "";
     }
    

    Definately not taking credit for this, I found it here:
    Programmer XR and modified it to my needs.

    Hopefully this will help other people out!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I want to count how many characters a certain string has in PHP, but

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.