• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

xml parsing in php

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
rvcw
Asked:
rvcw
1 Solution
 
gr8gonzoConsultantCommented:
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
 
rvcwAuthor Commented:
Hi,

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

object(SimpleXMLElement)#16 (2) { ["status"]=> string(1) "0" ["statusmsg"]=> string(17) "Permission Denied" }
0
 
rvcwAuthor Commented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
rvcwAuthor Commented:
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
 
gr8gonzoConsultantCommented:
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
 
gr8gonzoConsultantCommented:
That was to be an objection comment.
0
 
Ray PaseurCommented:
@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
 
South ModModeratorCommented:
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
 
rvcwAuthor Commented:
@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
 
gr8gonzoConsultantCommented:
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
 
rvcwAuthor Commented:
@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
 
gr8gonzoConsultantCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now