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

  • Home
  • SEARCH
  • 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 7828439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:21:24+00:00 2026-06-02T10:21:24+00:00

i call a web service that returns some HTML which enclosed in an XML

  • 0

i call a web service that returns some HTML which enclosed in an XML envelop… something like:

<xml version="1.0" cache="false">
    <text color="white">
        <p> Some text <br /> <p>
    </text>
</xml>

I use XmlPullParser to parse this XML/HTML. To get the text in element, i do the following:

case XmlPullParser.START_TAG:

    xmlNodeName = parser.getName();

    if (xmlNodeName.equalsIgnoreCase("text")) {
        String color = parser.getAttributeValue(null, "color");
        String text = parser.nextText();

        if (color.equalsIgnoreCase("white")) {

            detail.setDetail(Html.fromHtml(text).toString());

        }
    }
break;

This works well and gets the text or html in element even if it contains some html tags.

Issue arises when the element’s data starts with <p> tag as in above example. in this case the data is lost and text is empty.

How can i resolve this?

EDIT

Thanks to Nik & rajesh for pointing out that my service’s response is actually not a valid XML & element not closed properly. But i have no control over the service so i cannot edit whats returned. I wonder if there is something like HTML Agility that can parse any type of malformed HTML or can at least get whats in html tags .. like inside <text> … </text> in my case?? That would also be good.

OR anything else that i can use to parse what i get from the service will be good as long as its decently implementable.

Excuse me for my bad english

  • 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-06-02T10:21:25+00:00Added an answer on June 2, 2026 at 10:21 am

    Solution

    Isnpired by Martin’s approach of converting the received data first to string, i managed my problem in a kind of mixed approach.

    Convert the received InputStream’s value to string and replaced the erroneous tag with “” (or whatever you wish) : as follows

    InputStreamReader isr = new InputStreamReader(serviceReturnedStream);
    BufferedReader br = new BufferedReader(isr);
    StringBuilder xmlAsString = new StringBuilder(512);
    String line;
    try {
        while ((line = br.readLine()) != null) {
            xmlAsString.append(line.replace("<p>", "").replace("</p>", ""));
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    

    Now i have a string which contains correct XML data (for my case), so just use the normal XmlPullParser to parse it instead of manually parsing it myself:

    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(false);
    XmlPullParser parser = factory.newPullParser();
    parser.setInput(new StringReader(xmlAsString.toString()));
    

    Hope this helps someone!

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

Sidebar

Related Questions

I have a synchronous web service call that returns a message. I need to
I'm implementing a Web service that returns a JSON-encoded payload. If the service call
I have web service written that generates some data...can I call the web service
I got a JavaScript code I wrote that calls a web service returns some
I have a .net web service that takes some xml data. From within the
I have written a web service that returns some data as json. To display
We're trying to use Axis2 to call a web service that cannot use HTTP/1.1
I have a web service that I call via ajax that requires the user
Is there a public/government web service that I can call to find out what
I have a web service that wish to call, and I want to pass

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.