...

View Full Version : How can I add <?xml tag in php file



abduraooft
06-08-2007, 09:34 AM
Hi friends,

Is it posssible to add
<?xml version="1.0" encoding="UTF-8"?>
tag, before DOCTYPE as given in the w3 website, if I'm using a .php file ?

Please let me know..

thanks n regards,
art

_Aerospace_Eng_
06-08-2007, 09:50 AM
Yes but short open tags needs to be set to off. Personally though I wouldn't bother with that line as it will mess up the display of IE6. Its not required either. I'm going to go out on a limb here and guess that you probably have no idea what xml is or what that line is for.

abduraooft
06-08-2007, 10:24 AM
Yes but short open tags needs to be set to off. Personally though I wouldn't bother with that line as it will mess up the display of IE6. Its not required either. I'm going to go out on a limb here and guess that you probably have no idea what xml is or what that line is for.

Thanks for the reply
(even though I couldn't get the idea completely:rolleyes: )

I was just reading this one http://www.w3.org/TR/xhtml1/#strict

and the 5th item under this says

...however XHTML document authors are strongly encouraged to use XML declarations in all their documents...

It may not be for me atleast for now:o

croatiankid
06-08-2007, 05:39 PM
It also says
Such a declaration is required when the character encoding of the document is other than the default UTF-8 or UTF-16 and no encoding was determined by a higher-level protocol.

You should IMO always use UTF-8 character encoding. Read just a little bit about it and you'll see why.

Aerospace is right in that adding that before your doctype will put IE into quirks mode (non-standards mode), as will anything (that shows up in the source code) before the doctype.

felgall
06-08-2007, 08:05 PM
With shorttags on you can always write it as:

<? echo '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'; ?>

abduraooft
06-09-2007, 08:07 AM
With shorttags on you can always write it as:

<? echo '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'; ?>

Thank you so much,

This is exactly what I want.
But I couldn't see much description about this 'shorttag' from the web.

Could you please explain a little more ?

regards,
art.

abduraooft
06-09-2007, 08:21 AM
With shorttags on you can always write it as:

<? echo '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'; ?>

Thank you so much,

This is exactly what I wanted.
But I couldn't see much description about 'what is shorttag' from the web.

Could you please explain a little more ?

regards,
art.

_Aerospace_Eng_
06-09-2007, 10:41 AM
http://us.php.net/ini.core
Learn to read the manual.

short_open_tag boolean

Tells whether the short form (<? ?>) of PHP's open tag should be allowed. If you want to use PHP in combination with XML, you can disable this option in order to use <?xml ?> inline. Otherwise, you can print it with PHP, for example: <?php echo '<?xml version="1.0"'; ?>. Also if disabled, you must use the long form of the PHP open tag (<?php ?>).

Note: This directive also affects the shorthand <?=, which is identical to <? echo. Use of this shortcut requires short_open_tag to be on.

Blaher
06-10-2007, 12:34 PM
With shorttags on you can always write it as:

<? echo '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'; ?>

couldn't he just do this?


<?php
//code...
echo '<?xml version="1.0" encoding="utf-8" ?>\n';
//more code...
?>
As long as your code is encased as a literal, it shouldn't run it like it was part of the script. Also, it's always a good idea to use <?php, instead of just using <?.

In fact, I don't see a problem if you even used this:


<?xml version="1.0" encoding="utf-8" ?>
<?php
//code...
?>

It's always worked for me, but I use PHP 5.2, and I'm not certain if it'll work on older versions.

Of course, I always use ISO, and if the browser dosn't support ISO, I have it replace with UTF-8, so I always suggest doing something like this.



<?php
echo "<?xml version=\"1.0\" encoding=\"";
if (stristr($_SERVER["HTTP_ACCEPT_CHARSET"], "iso-8859-1"))
{
echo "iso-8859-1";
}
else
{
echo "utf-8";
}
echo "\" ?>\n";
//more code...
?>
But that's only if you like ISO.

abduraooft
06-12-2007, 01:35 PM
Thanks for the comments.



couldn't he just do this?
[code]
<?php
//code...
echo '<?xml version="1.0" encoding="utf-8" ?>\n';
//more code...
?>

The difference b/w

echo '<'.'?xml version="1.0" encoding="UTF-8"?'.'>';

and
echo '<?xml version="1.0" encoding="utf-8" ?>';

is its very easy to add a comment (//) in the first one where as not in the second one :D ,apart from that everything same.

Now, shall I ask one more question..

I've just gone through http://www.w3schools.com/xhtml/default.asp

and couldn't see an <?xml tag before any example document( or even in this sites source)

But http://www.w3.org/TR/xhtml1/#strict
mention about <?xml tag and this website's source has used it.

Are they using any special properties of xml for the building of this site?
Or What is the purpose of this tag here?
(Please give some helpful totorial links on this issue)

Thanks n regards,
art

Blaher
06-13-2007, 03:47 AM
The reason why it's useful to use the <?xml?> tag is for a few reasons.
When you validate any +xml document, on some validations they will recommend you have it.
You don't really need it in a lot of cases though, unless your using something other than xhtml in your source. The only reason I have it is to declare it's a xml document, and I like to throw my own tags sometimes before and after the document and use xsl to translate it. There may be other reasons why to declare it as a xml document, but none that I really use myself.

Also, if you have different browsing support, you could have both your xhtml, wml, rss, and maybe even your vxml on the same page and your browser (depending if it's web, rss viewer, a cellphone, or your phone calling a voxio server) should handle it.

I also seen something about Xlink and Xpath, but I never stopped yet and learned them or what they are.

abduraooft
06-13-2007, 09:36 AM
Wow.. nice explanation . Thanks.

Now I'm curious to know one more thing.

Is it possible to create an appealing website with xml+xslt only?
Any such pretty websites exist?
(I'm very new to xml and someone told me to concentrate more on xml rather than html)

regards,
art

Blaher
06-13-2007, 10:54 AM
Wow.. nice explanation . Thanks.

Now I'm curious to know one more thing.

Is it possible to create an appealing website with xml+xslt only?
Any such pretty websites exist?
(I'm very new to xml and someone told me to concentrate more on xml rather than html)

regards,
art

Yes, it is possible to do that. But you still have to use the html to translate it.
Here might be a example for you to use.
http://blahertech.dnsalias.net/_dev/sitemap.php
using the xsl file of
http://blahertech.dnsalias.net/_dev/templates/xsl.php

Although mine right now is a little buggy and I'm still working on it.
But overall, http://www.w3schools.com/xsl/ is a good place to learn how to use it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum