Solved

xml parsing in php

Posted on 2013-01-26
13
211 Views
Last Modified: 2013-02-08
Hi,

I'm having some problems parsing some content..

The var_dump of the content is:
object(SimpleXMLElement)#16 (2) { ["status"]=> string(1) "0" ["statusmsg"]=> string(17) "Permission Denied" }

Here is a snippet of some of my code:

        $this->load->helper('xmlapi');
        $xmlapi = new xmlapi($ip);
        $xmlapi->password_auth($user, $pass);
        $xmlapi->set_port(2087);
        $xmlapi->set_debug(1);

        $response = $xmlapi->removeacct("someuser");

        $xml2 = new SimpleXMLElement($response);
   
        print $xml2->statusmsg;

I get the error message:

A PHP Error was encountered

Severity: Warning

Message: SimpleXMLElement::__construct(): Entity: line 4: parser error : Start tag expected, '<' not found

Filename: controllers/missionControl.php

Line Number: 64

A PHP Error was encountered

Severity: Warning

Message: SimpleXMLElement::__construct():

Filename: controllers/missionControl.php

Line Number: 64

A PHP Error was encountered

Severity: Warning

Message: SimpleXMLElement::__construct(): ^

Filename: controllers/missionControl.php

Line Number: 64

Any help is much appreciated
0
Comment
Question by:rvcw
13 Comments
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 38822154
Sometimes people forget to really think about what the error message is saying.

"Message: SimpleXMLElement::__construct(): Entity: line 4: parser error : Start tag expected, '<' not found"

First, the location of the error... so the error is in the constructor, meaning that it's coming from trying to start a new instance of SimpleXMLElement, which looks to be here:

 $xml2 = new SimpleXMLElement($response);

Open in new window


The error message also indicates the line number of the code to be 64, so I would assume that also corresponds correctly. Next, the error itself: "Start tag expected, '<' not found"

So XML looks like "<something><blah></blah></something>", right? So naturally the parser would be looking for the beginning of the XML, which would start with the < character. It's saying it is expecting < but it didn't find it, so it found something else instead.

That means that whatever is in $response is probably not XML. Try echo-ing out $response instead and see what's in there. It might be some completely unrelated error message.
0
 

Author Comment

by:rvcw
ID: 38822160
Hi,

As I had posted, the content of $response is:

object(SimpleXMLElement)#16 (2) { ["status"]=> string(1) "0" ["statusmsg"]=> string(17) "Permission Denied" }
0
 

Author Comment

by:rvcw
ID: 38822174
figured it out..it's already a simplexmlelement so i shouldn't be converting it to one..

so I did $response->statusmsg and it worked.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:rvcw
ID: 38822230
I've requested that this question be closed as follows:

Accepted answer: 0 points for rvcw's comment #a38822174

for the following reason:

figured it out.
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 38822228
My answer is technically correct, which was that $response was not valid XML. I was trying to lead you down the path. Recommendation is to accept #a38822154 as the answer.
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 38822231
That was to be an objection comment.
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 38822393
@rvcw: Going forward, please post the test data you're using.  When we see that we have a much better chance of getting you to a good answer.  Unworking code almost never adds value!  SSCCE is your friend.  Best to all, ~Ray
0
 

Expert Comment

by:South Mod
ID: 38866305
I've requested that this question be closed as follows:

Accepted answer: 0 points for rvcw's comment #a38822174
Assisted answer: 500 points for gr8gonzo's comment #a38822154

for the following reason:

Starting the Auto-Close procedure on behalf of the question asker

SouthMod
Community Support Moderator
0
 

Author Comment

by:rvcw
ID: 38866320
@gr8gonzo

While I appreciate your willingness to help and your response, I didn't find it helpful and in fact it was very unhelpful. I'm unsure how telling me to read the error message was in any way providing any sort of direction to anything, I knew perfectly well what the error was and stated quite clearly what I didn't understand.
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 38866345
Wow... Really? Talk about being petty with points...

Re-read your question. I'll summarize:

Hi,

I'm having some problems parsing some content..

The var_dump of the content is:
<data>

Here is a snippet of some of my code:
<code>

I get the error message:
<error>

Any help is much appreciated

Open in new window


To me, that (especially the "Any help is much appreciated" part) says that you did NOT understand what the error was stating. Nowhere did you state "quite clearly" what you didn't understand - only that you were "having some problems." If you knew what the error was stating, then you would have been able to trace it back to the variable contents and you wouldn't have asked the question.

My entire post was simply an attempt to help someone through an error message. I came to the final point here:

"It's saying it is expecting < but it didn't find it, so it found something else instead.

That means that whatever is in $response is probably not XML."

Open in new window


What part of that was wrong (or unhelpful)? You clearly read that statement, since you then followed it up with describing the content and then it seemed like you realized the issue - that $response was not an XML string but an XML object.

Maybe I didn't just feed you the fish fast enough...

Whatever the case may be, I led you down the right path, you found the problem, and when I objected to you trying to say that you answered it yourself, and when an admin agrees with my assessment, you instead assign the points to a different answer that wasn't actually the answer to this issue.

Again, unbelievably petty. I'll make a note to never touch your questions again if this is what I can expect from you.
0
 

Author Comment

by:rvcw
ID: 38866398
@gr8gonzo

Firstly, there is no reason to be rude here. We're all adults, and we all have our strengths and weaknesses. I find your attitude very inappropriate in such an environment.

You spend more time telling me I'm wrong rather than actually helping.. Perhaps channel that effort into something productive instead of what seems to be quite childish remarks and your comments above do prove that. The points were awarded to the person that I found most helpful. You were very unhelpful.

The other poster provided a link to SSCCE which I found very helpful, much more helpful than "read your error message, go help yourself" approach that you took. You did not lead me down any path, I read your comment and thought to myself something very uncomplimentary about what you wrote.

" I'll make a note to never touch your questions again if this is what I can expect from you."

I would be grateful if you do that. Ultimately, if you have nothing helpful to say, then please do not say it at all.
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 38867890
And again you ignored the guts of this conversation. Let me summarize:

ME: ...whatever is in $response is probably not XML."

YOU: "figured it out..it's already a simplexmlelement so i shouldn't be converting it to one."

Suggestion, result, solution. If you "didn't find it helpful and in fact it was very unhelpful", and thought it was SO unhelpful that you in turn canceled the objection and the moderator's own agreement of my assessment JUST so you could assign the points to anyone but me, then you have a REALLY twisted sense of helpfulness.

Whatever helps you sleep at night. I'm detaching from this thread.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now