/    Sign up×
Community /Pin to ProfileBookmark

Hi all…
I am running an xml file, containing php, through my php interpreter… but there is a parsing error… the error occurs on the very first line, regardless of what that is, either <?xml or <?php. I think it has to do with the <? portion of the xml tag as the php interpreter gets confused, but Im not sure. Even if my xml document contains no php, running it through the parser still causes the same problem, so I know it has nothing to do with my php coding skills. And the xml file works properly without using the parser, so I know my xml is correctly written. This has everything to do with the php parser and how it interprets xml. Does anyone know whats wrong… or even if running an xml file through a php parser is even possible.

to post a comment
PHP

20 Comments(s)

Copy linkTweet thisAlerts:
@acorbelliJan 17.2006 — I'm not sure I quite understand this....why are you running an xml file through a php parser?
Copy linkTweet thisAlerts:
@bokehJan 17.2006 — why are you running an xml file through a php parser?[/QUOTE]Good question. There are good reasons but I'd like to here yours. By the way just echo the first line of your xml file.[code=php]// remove this
<?xml version="1.0" encoding="iso-8859-1"?>

// replace with this
<?php echo '<?xml version="1.0" encoding="iso-8859-1"?>' ?>[/code]
Copy linkTweet thisAlerts:
@squishyauthorJan 18.2006 — ok... so heres what I did... I echo'd the first couple of lines that contained <? and ?>, and that was it, left everything else outside of the php script, no other php was included. Doing this did generate the xml code perfectly on the clients side inside the browser, but as it is written in the xml file, as you would see it in the notepad, verbatim. But, the xml isnt being processed on the clients side as xml should be. Neither the normal tree branching thingy is generated for the xml, even though it is a .xml file, nor is the xml processed with the xslt file that accompanies it. This still doenst make sense... I should be able to do this, should I?

As for why do this? No reason whatsoever. I am trying to learn. The best way to learn is to understand what is going on, and without a tutor the best way to do that is through trial and error, practical experience. I have posts all throughout this site... most of which seem rediculous, I admit... but I have a good conceptual reason for asking. I find it more funny that other people who seem experienced at this and know all the 'hows' only scoff at me and ask 'why would you even try'. (not directed at you Anthony). I have a complete lack of imagination that I suffer from, I try to make up for it with a thorough understanding. Its one thing to effectively write code, and another to truly understand it, I think anyway. Thats my story, and Im sticking to it. ?
Copy linkTweet thisAlerts:
@Markbad311Jan 18.2006 — I know I for one will be trying to set up a feed soon enough I just have to research feeds. I had XML in school. as far as I know aside from PHP you shouldn't be having any of those errors
Copy linkTweet thisAlerts:
@squishyauthorJan 18.2006 — Im not sure what a feed is exactly. Does that have anything to do with databasing? That MySql stuff? I dont know anything about that yet.

I have tinkered a bit with php (fairly new to me still) but I have opened up, edited, and read from separate files using php. And I have also played with xml and xslt. But I only decided to try combining the two last night... with results I cant explain using my current understanding of both xml and php.

If one can process file contents in a php processor and have that sent to a remote browser, and have it display html properly, and have it display any file properly... then it should also work with an xml file. Thats all I did... I just routed an xml file through the php, other than that nothing was effected. That xml file was sent from my host to my browser via a php interpreter... but the client side isnt viewing it as xml.
Copy linkTweet thisAlerts:
@acorbelliJan 18.2006 — Good question. There are good reasons but I'd like to here yours. By the way just echo the first line of your xml file.[/QUOTE]

No, I mean, I can understand using PHP to lay out an XML document (thus having xml within the php, much as you would html within php)...but why would you run an xml only document through a php parser? I'm not sure if that's the only way you can do it with your server, or if there is a reason for it other than that?
Copy linkTweet thisAlerts:
@NogDogJan 18.2006 — You probably have [url=http://www.php.net/manual/en/ini.core.php#ini.short-open-tag]short open tags[/url] enabled on your PHP installation. Therefore, the PHP parser interprets [b]<?xml[/b] as two things: [b]<?[/b] as "start PHP code" followed by [b]xml[/b] as an undefined constant, likely generating a PHP syntax error. Thus the need to echo the <?xml tag from within your PHP code.
Copy linkTweet thisAlerts:
@squishyauthorJan 18.2006 — Im sorry, Im not quite sure what your asking.

I am running my own web server... all settings are correct. My php interpreter, as far as I know, is set up correctly as well. My browser is new and top of the line.

Question: Should I run the XSLT file through the parser as well? Would that fix this problem?

Heres what I am doing... I am using php to piece together data stored in "other" files, like .txt or whatever, into an xml format. That format is then displayed using the xslt style sheet. Three separate files working together.

I know there are plenty easier ways to do this... dont get me wrong. I am trying to make this work right solely because I dont see why it isnt.
Copy linkTweet thisAlerts:
@squishyauthorJan 18.2006 — NogDog... I dont know about that setting or not... but I have already attempted, on numerous occassions, to echo the <? portions... I have attempted this in a variety of ways.

Should I write it like this: <?php echo '<[B][/B]?xml



I can easily run any html through the php interpreter... and any other file for that matter, but when I try the xml file things just 'go wrong'
Copy linkTweet thisAlerts:
@NogDogJan 18.2006 — As long as you are echoing within single quotes, I don't think you should have to escape any characters within those quotes (other than single quotes, of course). Other than that, I really don't know enough about XML to know if there are other issues such as web server settings that could be affecting this. Perhaps you might want to pop over to the XML forum here and see if any gurus there have run into a similar problem?
Copy linkTweet thisAlerts:
@Markbad311Jan 18.2006 — here is a sample tut on using [URL=http://www.howtocreate.co.uk/tutorials/jsexamples/importingXML.html]JavaScript[/URL]
Copy linkTweet thisAlerts:
@bokehJan 18.2006 — but why would you run an xml only document through a php parser?[/QUOTE]It actually would have a negative effect. It would override Apache's default behaviour of sending 304 output for repeat requests on non-updated pages (wasting bandwidth). It also unnecessarily increases server load.
Copy linkTweet thisAlerts:
@squishyauthorJan 18.2006 — Well, Im not running Apache. And I am not trying to determine if this is a good idea or not... I am not turning this into a philosophical debate on the pros and cons. I am merely asking a technical question. Is it possible? And if so, how?

Please, no offense intended, but open your own thread for the "whys?" about it. I opened this one for the "hows?" and for the sake of others that are also curious. Scratch that, I dont mind discussing the "whys?," in fact I would like to, but not at the cost of dumping my initial question. This seems to be the general direction this is headed and I am not getting my question answered. If you really want to talk to me one on one about the "whys?" then write me at my email addy, nlsweeten1980 at yahoo.
Copy linkTweet thisAlerts:
@bokehJan 18.2006 — Scratch that, I dont mind discussing the "whys?," in fact I would like to, but not at the cost of dumping my initial question.[/QUOTE]Since your initial question has been answered by Nogdog and myself what additional information do you require as to '[I]how[/I]' to do it? As to the '[I]why[/I]' you wish to do it, I don't see why you don't just explain '[I]why[/I]' to those who are interested. In an earlier post you said you are doing this because '[I]you are trying to learn[/I]', well trying to suppress further discussion is not going to help that cause now is it?
Copy linkTweet thisAlerts:
@squishyauthorJan 19.2006 — I dont see as to how your posts have helped... I know that doing this in this fashion is a bad idea, aparently... that doesnt change the fact that your advice has yet to yield results. My problem persists. Though your advice and comments have been and will continue to be useful to me, I still cant run an xml file through a php interpreter. How does explaining to me the benefits or disbenefits to making this attempt, or me explaining why Im doing it, helpful in finding a solution? My personal reasons dont matter, but the fact that there is a techinical issue that "I" need resolving does. I am not trying to be offensive or start some poo, I am just trying to figure out how to do something that seems to me should be easily done. As far as I am concerned, if I cant do something that seems extremely basic poses a serious problem to me. Try it yourself, run an xml file through the php parser, see what you get. If it works, tell me what you did. If it doesnt work then dont just ignore it because you have no use for it, but figure it out (for your own sake... or mine.) If its not possible, so be it... I dont care... it doesnt effects me one bit... I just want to know. Simple as that. This isnt the first post Ive made where people go off on some wild tangent vaguely related to my original post, quite frankly its starting to annoy me. Can anyone refer me to a website where I [I]can[/I] get my questions answered?
Copy linkTweet thisAlerts:
@NogDogJan 19.2006 — How about:
[code=php]
<?php
header("Content-Type: application/xml; charset=ISO-8859-1");
echo '<?xml.......>';
// etc.....
?>
[/code]
Copy linkTweet thisAlerts:
@acorbelliJan 19.2006 — He told you earlier squishy, turn off the option on your web server that translates "<?" into "<?php" because it's looking at "<?xml" as "<?php xml" and is not able to find the constant named "xml".

And the questioning was because I was curious if you had some special reason that I might want to know about for running the xml file through a php parser. No need to be so defensive over simple curiosity on our parts.
Copy linkTweet thisAlerts:
@acorbelliJan 19.2006 — You probably have [url=http://www.php.net/manual/en/ini.core.php#ini.short-open-tag]short open tags[/url] enabled on your PHP installation. Therefore, the PHP parser interprets [b]<?xml[/b] as two things: [b]<?[/b] as "start PHP code" followed by [b]xml[/b] as an undefined constant, likely generating a PHP syntax error. Thus the need to echo the <?xml tag from within your PHP code.[/QUOTE]

This is what I was referring to, so you either should disable "short open tags" or use PHP to echo <?xml
Copy linkTweet thisAlerts:
@bokehJan 19.2006 — [URL=http://www.webdeveloper.com/forum/showthread.php?t=89132]Read this thread![/URL] It contains lots of info about what you are trying to do.
Copy linkTweet thisAlerts:
@squishyauthorJan 19.2006 — Well everyone. I apologize for getting short... its just that people tend to redirect my threads to the point where my reason for posting in the first place is completely abandoned... its happened many times... not just on this site but on others too... its just irritating, Im sure you can understand.

As for my problem... I havent checked this thread in a day or two, so unfortunately I missed out on your posts... but I have independantly solved the problem. I didnt do what was suggested by anyone. I dont know why this mattered... but heres what I did. I turned <?php echo " bunch of xml crap with single quotes "; ?> into <?php echo ' bunch of xml crap with double quotes '; ?>. It works fine now... go figure! I would like to know why this happened, as Im sure some of you are curious too.

I dont know how to change the php settings within the parser itself... but I will have to learn I suppose.

As for why I tried this... I just wanted to learn php and xml better, and more specifically how to integrate them... no specific reason or example, but just to know. The application that I programmed uses php to extract and convert the contents of one or more txt and/or doc files into a single xml file format, which is sent to the browser. With the associated xslt file its displayed accordingly. I dont know if its practical or efficient... I did it just to see if I could, for my own practice and understanding.

Anyway, thanks for your help... I will undoubtedly need more later. Hope you all dont think Im an ass... lol... anywho, thanks again.
×

Success!

Help @squishy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...