Solved

xml parsing in php

Posted on 2013-01-26
13
208 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:rvcw
Comment Utility
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
Comment Utility
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
Comment Utility
That was to be an objection comment.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
@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
Comment Utility
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
Comment Utility
@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
Comment Utility
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
Comment Utility
@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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

771 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

13 Experts available now in Live!

Get 1:1 Help Now