473,465 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Saving XML file with iso-8859-1 encoding fails

Hi,
The question might sound (and probably is;-) stupid, but why doesnt the
follwing code work?? Is there something i dont see?

$doc = new DOMDocument('1.0', 'iso-8859-1');
$doc->formatOutput = true;

$root = $doc->createElement('root');
$root = $doc->appendChild($root);

$head = $doc->createElement('head');
$head = $root->appendChild($head);

$title = $doc->createElement('title');
$title = $head->appendChild($title);

/* probably the real sign gets killed,
so here is the html: ä (an umlaut) */
$text = $doc->createTextNode('ä');
$text = $title->appendChild($text);
echo $doc->saveXML();

Thanks in advance
Jul 17 '05 #1
6 5890
Börni wrote:
Hi,
The question might sound (and probably is;-) stupid, but why doesnt the
follwing code work?? Is there something i dont see?

$doc = new DOMDocument('1.0', 'iso-8859-1');
$doc->formatOutput = true;

$root = $doc->createElement('root');
$root = $doc->appendChild($root);

$head = $doc->createElement('head');
$head = $root->appendChild($head);

$title = $doc->createElement('title');
$title = $head->appendChild($title);

/* probably the real sign gets killed,
so here is the html: ä (an umlaut) */
$text = $doc->createTextNode('ä');
$text = $title->appendChild($text);
echo $doc->saveXML();

Thanks in advance


Sorry i forgot to post the error!

Warning: output conversion failed due to conv error in /websites/dom.php
on line 22

Warning: Bytes: 0xE4 0x3C 0x2F 0x74 in /websites/dom.php on line 22
Jul 17 '05 #2
On Mon, 07 Feb 2005 20:19:05 +0000, Börni <b.******@onlinehome.de> wrote:
Hi,
The question might sound (and probably is;-) stupid, but why doesnt the
follwing code work?? Is there something i dont see?

$doc = new DOMDocument('1.0', 'iso-8859-1');
$doc->formatOutput = true;

$root = $doc->createElement('root');
$root = $doc->appendChild($root);

$head = $doc->createElement('head');
$head = $root->appendChild($head);

$title = $doc->createElement('title');
$title = $head->appendChild($title);

/* probably the real sign gets killed,
so here is the html: &auml; (an umlaut) */
$text = $doc->createTextNode('ä');
$text = $title->appendChild($text);
echo $doc->saveXML();

Thanks in advance


The user notes on:

http://uk2.php.net/manual/en/functio...-text-node.php

claim:

"all text methods in domxml expect utf-8 encoded strings as input."

... and recommend using utf8_eecode() on the value.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #3
Andy Hassall wrote:
On Mon, 07 Feb 2005 20:19:05 +0000, Börni <b.******@onlinehome.de> wrote:

Hi,
The question might sound (and probably is;-) stupid, but why doesnt the
follwing code work?? Is there something i dont see?

$doc = new DOMDocument('1.0', 'iso-8859-1');
$doc->formatOutput = true;

$root = $doc->createElement('root');
$root = $doc->appendChild($root);

$head = $doc->createElement('head');
$head = $root->appendChild($head);

$title = $doc->createElement('title');
$title = $head->appendChild($title);

/* probably the real sign gets killed,
so here is the html: &auml; (an umlaut) */
$text = $doc->createTextNode('ä');
$text = $title->appendChild($text);
echo $doc->saveXML();

Thanks in advance

The user notes on:

http://uk2.php.net/manual/en/functio...-text-node.php

claim:

"all text methods in domxml expect utf-8 encoded strings as input."

... and recommend using utf8_eecode() on the value.

Ok, but why then can i specifiy the encoding for the file?!
Jul 17 '05 #4
On Mon, 07 Feb 2005 21:48:59 +0000, Börni <b.******@onlinehome.de> wrote:
Andy Hassall wrote:
On Mon, 07 Feb 2005 20:19:05 +0000, Börni <b.******@onlinehome.de> wrote:

The user notes on:

http://uk2.php.net/manual/en/functio...-text-node.php

claim:

"all text methods in domxml expect utf-8 encoded strings as input."

... and recommend using utf8_eecode() on the value.

Ok, but why then can i specifiy the encoding for the file?!


You apparently need to pass all text into the functions as utf8 - and only
then when the XML is finally output is it re-encoded into the encoding you
specified.

Consider:

andyh@server:~/public_html$ cat test.php
<?php
$doc = new DOMDocument('1.0', 'iso-8859-1');
$doc->formatOutput = true;

$root = $doc->createElement('root');
$root = $doc->appendChild($root);

$head = $doc->createElement('head');
$head = $root->appendChild($head);

$title = $doc->createElement('title');
$title = $head->appendChild($title);

/* probably the real sign gets killed,
so here is the html: &auml; (an umlaut) */
$text = $doc->createTextNode(utf8_encode('ä'));
$text = $title->appendChild($text);

echo $doc->saveXML();
?>
andyh@server:~/public_html$ php -q test.php | hexdump -C
00000000 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 |<?xml version="1|
00000010 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 69 73 |.0" encoding="is|
00000020 6f 2d 38 38 35 39 2d 31 22 3f 3e 0a 3c 72 6f 6f |o-8859-1"?>.<roo|
00000030 74 3e 0a 20 20 3c 68 65 61 64 3e 0a 20 20 20 20 |t>. <head>. |
00000040 3c 74 69 74 6c 65 3e e4 3c 2f 74 69 74 6c 65 3e |<title>ä</title>|
00000050 0a 20 20 3c 2f 68 65 61 64 3e 0a 3c 2f 72 6f 6f |. </head>.</roo|
00000060 74 3e 0a |t>.|
00000063

Note that the ä has indeed come out in iso-8859-1, i.e a single byte, and not
in utf8.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #5
Hello,

on 02/07/2005 06:19 PM Börni said the following:
Hi,
The question might sound (and probably is;-) stupid, but why doesnt the
follwing code work?? Is there something i dont see?

$doc = new DOMDocument('1.0', 'iso-8859-1');
$doc->formatOutput = true;

$root = $doc->createElement('root');
$root = $doc->appendChild($root);

$head = $doc->createElement('head');
$head = $root->appendChild($head);

$title = $doc->createElement('title');
$title = $head->appendChild($title);

/* probably the real sign gets killed,
so here is the html: &auml; (an umlaut) */
$text = $doc->createTextNode('ä');
$text = $title->appendChild($text);


echo $doc->saveXML();

Thanks in advance


You may want to try this class XML writer class that lets you specify
the input and output encoding either as ISO-8859-1 or UTF-8. It does not
require any special extension.

http://www.phpclasses.org/xmlwriter

--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #6
Manuel Lemos wrote:
Hello,

You may want to try this class XML writer class that lets you specify
the input and output encoding either as ISO-8859-1 or UTF-8. It does not
require any special extension.

http://www.phpclasses.org/xmlwriter


Thanks, i will look closer at that class!
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: john bailo | last post by:
For a c# program to automatically extract information from email attachments using the Outlook 9 OM, rather than saving to a file, then reading the file, I would prefer to 'Save' the attachment to...
0
by: marfi95 | last post by:
I'm automating a piece of my app to allow my customers to send me a copy of their event logs (for diagnostics) on demand just through the click of a button. I know I can use the...
7
by: juli | last post by:
I want to save file ,using the SaveFileDialog control, in such way that uploaded file will be saved always as "text.txt" and always in c:\Text folder. How do I do it? Thank you a lot and Happy...
4
by: zombek | last post by:
I'm making a small program which takes a folder with images and generates optimized normal-sized images and thumbnails using Python Imaging Lbrary (PIL). The problem is here: ........
2
by: zorro | last post by:
Hello, When I upload an image to the server I get the message: Warning: Only -1 bytes were written, expected to write 547 The server phpinfo lists : file_uploads On
6
by: Mark Denardo | last post by:
My question is similar to one someone posted a few months back, but I don't see any replies. Basically I want to be able to have users upload photos and save them in a database (as byte data)...
1
by: John | last post by:
Hi I am using an open file dialog which allows me to select a file to open. This is all great. But it does not allow me to give a filename and select folder to save the file to if the file does...
0
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hi, We have a legacy asp application that uses a third party component to upload a file and saves it to a secure network share. The code sets the credentials for the secure network share on the...
2
by: deathprincess | last post by:
Hi, I'm writing a code in c# that will export a table to excel file ".xls". I want to save every file with different filename and worksheets of each as sheet 1. i have no idea how to format the...
5
by: JohnLorac | last post by:
Hello, can somebody help me with saving file into local disk using javascript? I made some sample code which unfortunately won't work :(. Applet sample file: public class IO extends...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.