Jump to content

Archived

This topic is now archived and is closed to further replies.

ksassa

xml declaration in html file causing problems?

Recommended Posts

I have the following html file

[code]<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- apples.html
     The contents of the apple frame (displayed in second frame of frames.html)
     of frames.html - a general description of fruit
     -->
<html xmlns = "http://www.w3.org/1999/xhtml">
  <head> <title> Apple Information </title>
  </head>
  <body>
    <p>
      Apple is the common name for any tree of the genus Malus, of
      the family Rosaceae. Apple trees grow in any of the temperate
      areas of the world. Some apple blossoms are white, but most
      have stripes or tints of rose. Some apple blossoms are bright
      red. Apples have a firm and fleshy structure that grows from
      the blossom. The colors of apples range from green to very
      dark red. The wood of apple trees is fine-grained and hard.
      It is, therefore, good for furniture construction. Apple trees
      have been grown for many centuries. They are propagated by
      grafting because they do not reproduce themselves.
    </p>
  </body>
</html>
[/code]

I am also running Apache which I obtained from [url=http://www.apachefriends.org/en/xampp.html]http://www.apachefriends.org/en/xampp.html[/url]. When I open up IE6 and go to http://localhost/apples.html, I find that the html file is displayed like an xml file would be with a listing of all the html tags and content. But if I take out the xml declaration, IE6 displays the html file properly. I also discovered that if I leave the xml declaration in and take out the comment or make it very short, then IE6 displays the html file properly. In addition, if I open up Windows Explorer and navigate to where apples.html is located on my hard drive and double click on it, the html file is displayed properly by IE.  Moreover, I find that Mozilla Firefox displays it properly all the time. Does any one know why this is happeneing? Is the xml declaration causing problems?

Share this post


Link to post
Share on other sites
I believe you are saving the above file and .php.  If thats the case you need to write the code this this:

[code]<?='<?xml version = "1.0" encoding = "utf-8"?>';?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
  <head> <title> Apple Information </title>
  </head>
  <body>
    <p>
      Apple is the common name for any tree of the genus Malus, of
      the family Rosaceae. Apple trees grow in any of the temperate
      areas of the world. Some apple blossoms are white, but most
      have stripes or tints of rose. Some apple blossoms are bright
      red. Apples have a firm and fleshy structure that grows from
      the blossom. The colors of apples range from green to very
      dark red. The wood of apple trees is fine-grained and hard.
      It is, therefore, good for furniture construction. Apple trees
      have been grown for many centuries. They are propagated by
      grafting because they do not reproduce themselves.
    </p>
  </body>
</html>[/code]

Share this post


Link to post
Share on other sites
What?  First of all, NEVER use short tags.  Second of all, I have no idea what that would do for him.

Share this post


Link to post
Share on other sites
While you are right about not using short tags, he is right about what he said.  When echoing out an XML declaration in PHP, PHP thinks the closing xml tag is a closing php tag, and it screws everything up. As a result, escaping the brackets is necessary, though I prefer just to exit out of php altogether, output the xml declaration directly as text, then enter back into php if necessary.

Share this post


Link to post
Share on other sites
Good to know. My company just bought a site recently in which the original coder used short tags, and our server doesn't allow them. That means I spent a whole lot of time going through and finding all the short tags and turning them into long tags. Pain in the ass.

Share this post


Link to post
Share on other sites
[quote author=haku link=topic=110761.msg985174#msg985174 date=1220837262]
While you are right about not using short tags, he is right about what he said.  When echoing out an XML declaration in PHP, PHP thinks the closing xml tag is a closing php tag, and it screws everything up. As a result, escaping the brackets is necessary, though I prefer just to exit out of php altogether, output the xml declaration directly as text, then enter back into php if necessary.
[/quote]

That's why you turn short tags off. Then you don't have such problems.

Share this post


Link to post
Share on other sites
There is no such thing as a closing short tag. PHP closing tags and XML closing tags are identical. Turning off short tags will not solve the problem, the closing xml tag will still close the PHP and cause problems. Which is why the method he posted above solves the problem.

Share this post


Link to post
Share on other sites
[quote author=haku link=topic=110761.msg986001#msg986001 date=1220915908]
There is no such thing as a closing short tag. PHP closing tags and XML closing tags are identical. Turning off short tags will not solve the problem, the closing xml tag will still close the PHP and cause problems. Which is why the method he posted above solves the problem.
[/quote]

Turning off short tags means that the starting <? of the xml declaration won't start a PHP block.

Share this post


Link to post
Share on other sites
YPHP has already been started. The XML starting tag doesn't matter, because PHP has already been started. But the ending tag of the XML declaration ends [i]PHP[/i] as well as XML.

I don't know where you got this starting tag thing, I never mentioned anything about a starting tag, and no one else did either. However I have mentioned the closing tag a number of times.

Whether short tags are on or off, if PHP has been entered, the closing tag of the XML declaration will close the PHP.

Share this post


Link to post
Share on other sites
[quote author=haku link=topic=110761.msg986087#msg986087 date=1220923163]
YPHP has already been started. The XML starting tag doesn't matter, because PHP has already been started. But the ending tag of the XML declaration ends [i]PHP[/i] as well as XML.

I don't know where you got this starting tag thing, I never mentioned anything about a starting tag, and no one else did either. However I have mentioned the closing tag a number of times.

Whether short tags are on or off, if PHP has been entered, the closing tag of the XML declaration will close the PHP.
[/quote]

Wait, I don't even know how this topic got brought up...He wasn't using PHP for the XML tags in the original post.  Wth are we talking about?

Share this post


Link to post
Share on other sites
It's all there for you to see, but Rochakuchouhan said:

[quote]I believe you are saving the above file and .php.  If thats the case you need to write the code this this:[/quote]

His English was maybe not the best, but he was supposing that the OP was trying to echo out an xml statement using php. You replied in a manner like he didn't know what he was talking about, and I pointed out that he in fact did, as echoing out an XML declaration in PHP can cause problems.

As for whether or not the OP was using php or not, he didn't say, but the problems that he described made it appear very likely that he was, and that he was trying to echo out the XML declaration with it.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.