tags:

views:

75

answers:

2

Hi all,

I have to insert the xml processing instruction into xml file without opening that file means i have to insert that through PHP.anyone please helpme.

A: 

I guess with "XML processing instruction" you mean basically something like

<?xml version="1.0" ?>

Please note, that this is (as per spec) no processing instruction and will in all DOM tools never appear as one.

If you try to output this in PHP and find problems you most likely have the PHP.ini's short_open_tag directive set to On. Two possibilities:

  1. Set short_open_tags = Off in your php.ini

  2. echo the stuff:

-

echo '<?xml version="1.0"?>'."\n";
Boldewyn
What does this mean: "no processing instruction and will in all DOM tools never appear as one." ?
Ollie Saunders
The definition of a processing instruction is [defined in the XML spec](http://www.w3.org/TR/REC-xml/#sec-pi) and is distinct from an [XML declaration](http://www.w3.org/TR/REC-xml/#NT-XMLDecl).
Ollie Saunders
Yes and two paragrpahs before the *XML Declaration* is defined. So, XML Declaration != Processing Instruction.
Boldewyn
If you don't trust me, perhaps [xml.com](http://www.xml.com/pub/a/2002/09/04/xslt.html)?
Boldewyn
Or the XPath spec (http://www.w3.org/TR/xpath), point 5.5
Boldewyn
Or XSLT: http://www.w3.org/TR/xslt point 7.3 (sorry, I couldn't resist. I'll stop now.)
Boldewyn
A: 

That can't be done without opening the file. How else are you supposed to get the data? Even functions such as file_get_contents() cause the file to be opened, it just closes it again immediately after. If this is not what you mean by open you might want to edit your question.

Ollie Saunders