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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:46:18+00:00 2026-05-15T07:46:18+00:00

Please can somebody show me a simple example of parsing some HTML using libxml.

  • 0

Please can somebody show me a simple example of parsing some HTML using libxml.

#import <libxml2/libxml/HTMLparser.h>

NSString *html = @"<ul>"
    "<li><input type=\"image\" name=\"input1\" value=\"string1value\" /></li>"
    "<li><input type=\"image\" name=\"input2\" value=\"string2value\" /></li>"
  "</ul>"
  "<span class=\"spantext\"><b>Hello World 1</b></span>"
  "<span class=\"spantext\"><b>Hello World 2</b></span>";

1) Say I want to parse the value of the input whose name = input2.

Should output “string2value”.

2) Say I want to parse the inner contents of each span tag whose class = spantext.

Should output: “Hello World 1” and “Hello World 2”.

  • 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-15T07:46:19+00:00Added an answer on May 15, 2026 at 7:46 am

    I used Ben Reeves’ HTML Parser to achieve what I wanted:

    NSError *error = nil;
    NSString *html = 
        @"<ul>"
            "<li><input type='image' name='input1' value='string1value' /></li>"
            "<li><input type='image' name='input2' value='string2value' /></li>"
        "</ul>"
        "<span class='spantext'><b>Hello World 1</b></span>"
        "<span class='spantext'><b>Hello World 2</b></span>";
    HTMLParser *parser = [[HTMLParser alloc] initWithString:html error:&error];
    
    if (error) {
        NSLog(@"Error: %@", error);
        return;
    }
    
    HTMLNode *bodyNode = [parser body];
    
    NSArray *inputNodes = [bodyNode findChildTags:@"input"];
    
    for (HTMLNode *inputNode in inputNodes) {
        if ([[inputNode getAttributeNamed:@"name"] isEqualToString:@"input2"]) {
            NSLog(@"%@", [inputNode getAttributeNamed:@"value"]); //Answer to first question
        }
    }
    
    NSArray *spanNodes = [bodyNode findChildTags:@"span"];
    
    for (HTMLNode *spanNode in spanNodes) {
        if ([[spanNode getAttributeNamed:@"class"] isEqualToString:@"spantext"]) {
            NSLog(@"%@", [spanNode allContents]); //Answer to second question
        }
    }
    
    [parser release];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 535k
  • Answers 535k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There are several options if you want to stick with… May 17, 2026 at 1:01 am
  • Editorial Team
    Editorial Team added an answer Objects in a set are immutable; if you want to… May 17, 2026 at 1:01 am
  • Editorial Team
    Editorial Team added an answer I find found the answer in the apple developer website.… May 17, 2026 at 1:01 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Can somebody please show me how to do a Java regex that takes in
Can somebody post a simple html code on how to implement it,with simple data
Can somebody please help me fix my code.? I can't see where I'm going
Can somebody please point out the error in this code? function inspect(useDoubleQuotes) { var
can somebody please tell me where i m wrong why this RMI chat application
I have created an IEnumerable list of racing drivers using LINQ from a string
I am using jquery(newbie for jquery) in my application. In short what I am
I'm in the process of creating a blog for somebody. They want to pull
I have this method in a class I am using def binary_search(a,x) # ...
I am developing controls for WP7 application. I am aware that I can quickly

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.