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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:53:11+00:00 2026-06-02T04:53:11+00:00

Having a hard time parsing XML created from a web-form using POST. Here’s the

  • 0

Having a hard time parsing XML created from a web-form using POST.

Here’s the scenario:

1) User comes to a web-page, enters their name into a text-field, and clicks SUBMIT

2) This calls a PHP file (called “makeXML.php”) which generates an XML file containing that user’s name in a tag called “currentUserName”

3) an iPhone App then loads this “makeXML.php” file (using ‘loadXMLByURL’) and parses it, looking specifically to output the contents of the “currentUserName” tag into a UILabel object.

Should be pretty simple – but for some reason, the contents of the “currentUserName” tag are coming up empty in the App – though they show up perfectly well in the generated XML code in the browser.

What’s even stranger, is that if I instead hard-code a value to “uName” in the PHP file (“makeXML.php”) – as opposed to getting that value from the FORM (using $_POST[“userName”];) – it all works perfectly well. I’m able to grab the value from the “currentUserName” tag and output it to the UILabel object.

NSXMLParser seems to just not like POST’ed values for some reason.

Any ideas?

Here’s the code:

portal.html:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Web-Form</title>
</head>

<body>

<form name="form1" method="post" action="makeXML.php">
  <p>Enter your name:</p>
  <p>
    <input name="userName" type="text" />
  </p>
  <p>
    <input type="submit" value="SUBMIT" />
  </p>
</form>

</body>
</html>

Here is “makeXML.php”:

<?php
header("Content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";

echo "<document>";

$uName = $_POST["userName"]; 

echo "Here is the name you typed:";
echo "<br/>";
echo "<theUsersName>$uName</theUsersName>";

echo "</document>";

?>

Here is the outputted code from makeXML.php: (Note that this code comes out all on one line – is that how its supposed to be? Shouldn’t the “br” tag be working and forcing a line break there?)

<?xml version="1.0" encoding="UTF-8" ?><document>Here is the name you typed:<br/><theUsersName>johnson</theUsersName></document>

Again, note that if I replace:

    $uName = $_POST["userName"]; 

with plain-old:

    $uName = "John"; 

Everything works perfectly and the name “John” appears correctly in my UILabel…

  • 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-02T04:53:12+00:00Added an answer on June 2, 2026 at 4:53 am

    As psoft alluded to in his comments, it is hard to concretely answer a question such as this since your end goal seems somewhat unclear. I will assume that you are just starting to experiment with all of the involved technologies.

    Your PHP script will work, I have tested it on my local Apache server. Although there are some oddities; Such as inserting an html <br/> into XML. XML is a data format(At least in this context), not really intended for presentation. Your html file also works fine.

    There are three super-obvious ways to go from where you are.

    1) Do what your above comment says. Use a script to write to a database then use another to access it. The first from a webpage the second from objective-c code. I’m fairly sure this is not something you want to try right now.

    2) Interrupt the sending of the post from a UIWebView in your application. Send that data to your server by other means and parse the results.

    3) Ignore the web-view and just send the arguments to the server directly.

    Both 2 & 3 are very related. The main difference is the origin of the NSURLRequest.

    For 2, obtaining the post request is pretty easy. First you would set some object, let’s say your view controller, as the web-view’s delegate. Then implement the following method.

    -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
        // Very simple example of checking for the php script in the url
        if ([request.URL.absoluteString.lastPathComponent isEqualToString:@"makeXML.php"]){
            // Use the "request" parameter to
            // post the request yourself
            return NO; // Because you will handle it.
        } else {
            return YES;
        }
    }
    

    For 3, You simply create the NSURLRequest yourself and configure it for your needs. This requires the NSMutableURLRequest subclass.

    NSString *nameToPost = @"Mr Ducky";
    
    NSURL *url = [[NSURL alloc] initWithString:@"http://Address&FolderOfScriptHere/makeXML.php"];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
    request.HTTPMethod = @"POST";
    [request setHTTPBody:[[NSString stringWithFormat:@"userName=%@",nameToPost] dataUsingEncoding:NSUTF8StringEncoding]];
    

    And then in either case (2 or 3) you can use request to load the data to be parsed. Here is, for example, a very bad (synchronous) way to load the data.

    NSData *xmlData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    

    This data can then be fed to a parser or for testing simply be logged:

    NSString *xmlString = [[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding];
    NSLog(@"xml:%@",xmlString);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a hard time Parsing/Formatting a Date string received back from a web
I'm having a hard time passing data to my model using viewbag. Here is
I'm having a hard time parsing this. I know how to get the key
I'm having hard time trying to figure out how to auto-save user data in
I'm having hard time to find out how to read and write from /into
I'm having hard time trying to use teasers post in my wordpress theme (based
I was given this code earlier but am having a hard time parsing the
I'm having hard time understanding the following C# code. This code was taken from
I am having hard time trying to generate PDF files containing Greek letters using
Hehe I'm having hard time on choosing the question title. But let me explain

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.