Jump to content


Photo

xml declaration in html file causing problems?


  • Please log in to reply
11 replies to this topic

#1 ksassa

ksassa
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 07 October 2006 - 02:10 AM

I have the following html file

<?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>

I am also running Apache which I obtained from http://www.apachefri...g/en/xampp.html. 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?

#2 rochakchauhan

rochakchauhan
  • Members
  • PipPip
  • Member
  • 18 posts
  • LocationChandigarh

Posted 07 September 2008 - 06:27 AM

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

<?='<?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>


#3 DarkWater

DarkWater
  • Members
  • PipPipPip
  • Advanced Member
  • 6,175 posts
  • LocationNew York

Posted 08 September 2008 - 12:35 AM

What?  First of all, NEVER use short tags.  Second of all, I have no idea what that would do for him.
Info:Apache 2.2.4 | PHP 6.0.0-dev, PHP 5.2.4 | Ubuntu 8.04 | Age: 16 | Coding PHP and CSS+(X)HTML: 5-6 years | Feel free to PM me if you need help!
Αν χρειάζεσαι ένας μεταφραστής, μπορέις να μου μιλάς.  Μιλώ καλά.

If you ask for a banana, would you expect someone to hand you an orange? Or a fork?  No you wouldn't, because you asked for a banana, and you expect them to understand that a banana is not an orange or a fork.  It's the same principle.


#4 haku

haku
  • Staff Alumni
  • Advanced Member
  • 6,179 posts

Posted 08 September 2008 - 01:27 AM

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.

#5 TheFilmGod

TheFilmGod
  • Members
  • PipPipPip
  • Advanced Member
  • 1,941 posts
  • LocationNew Jersey

Posted 08 September 2008 - 02:22 AM

That is why php6 has completely dropped support for php short tags...  ;)
The future is here.

#6 haku

haku
  • Staff Alumni
  • Advanced Member
  • 6,179 posts

Posted 08 September 2008 - 05:18 AM

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.

#7 DarkWater

DarkWater
  • Members
  • PipPipPip
  • Advanced Member
  • 6,175 posts
  • LocationNew York

Posted 08 September 2008 - 08:13 PM

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.


That's why you turn short tags off. Then you don't have such problems.
Info:Apache 2.2.4 | PHP 6.0.0-dev, PHP 5.2.4 | Ubuntu 8.04 | Age: 16 | Coding PHP and CSS+(X)HTML: 5-6 years | Feel free to PM me if you need help!
Αν χρειάζεσαι ένας μεταφραστής, μπορέις να μου μιλάς.  Μιλώ καλά.

If you ask for a banana, would you expect someone to hand you an orange? Or a fork?  No you wouldn't, because you asked for a banana, and you expect them to understand that a banana is not an orange or a fork.  It's the same principle.


#8 haku

haku
  • Staff Alumni
  • Advanced Member
  • 6,179 posts

Posted 08 September 2008 - 11:18 PM

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.

#9 DarkWater

DarkWater
  • Members
  • PipPipPip
  • Advanced Member
  • 6,175 posts
  • LocationNew York

Posted 08 September 2008 - 11:39 PM

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.


Turning off short tags means that the starting <? of the xml declaration won't start a PHP block.
Info:Apache 2.2.4 | PHP 6.0.0-dev, PHP 5.2.4 | Ubuntu 8.04 | Age: 16 | Coding PHP and CSS+(X)HTML: 5-6 years | Feel free to PM me if you need help!
Αν χρειάζεσαι ένας μεταφραστής, μπορέις να μου μιλάς.  Μιλώ καλά.

If you ask for a banana, would you expect someone to hand you an orange? Or a fork?  No you wouldn't, because you asked for a banana, and you expect them to understand that a banana is not an orange or a fork.  It's the same principle.


#10 haku

haku
  • Staff Alumni
  • Advanced Member
  • 6,179 posts

Posted 09 September 2008 - 01:19 AM

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 PHP 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.

#11 DarkWater

DarkWater
  • Members
  • PipPipPip
  • Advanced Member
  • 6,175 posts
  • LocationNew York

Posted 09 September 2008 - 01:28 AM

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 PHP 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.


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?
Info:Apache 2.2.4 | PHP 6.0.0-dev, PHP 5.2.4 | Ubuntu 8.04 | Age: 16 | Coding PHP and CSS+(X)HTML: 5-6 years | Feel free to PM me if you need help!
Αν χρειάζεσαι ένας μεταφραστής, μπορέις να μου μιλάς.  Μιλώ καλά.

If you ask for a banana, would you expect someone to hand you an orange? Or a fork?  No you wouldn't, because you asked for a banana, and you expect them to understand that a banana is not an orange or a fork.  It's the same principle.


#12 haku

haku
  • Staff Alumni
  • Advanced Member
  • 6,179 posts

Posted 09 September 2008 - 01:56 AM

It's all there for you to see, but Rochakuchouhan said:

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


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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users