0

So the xml has: <?xml version="1.0" encoding="ISO-8859-15"?> and I'm supposed to load some of the nodes values and save to them. What encodings am I supposed to use? At the moment I'm using utf8_encode() which is kind of silly, but it works on save, but when I have to load the value again, it having scandic characters "ÅÄÖ", it shows like "Ääliö".

What can I use to encode the string to save and load to/from xml on php? The thing here is with the Scandinavian characters..

edit: sorry, i forgot to put the xml tag in {}...

edit: At the moment I'm using DOM Xpath to read and modify the xml file.

2 Answers 2

1

You aren't supposed to use any encodings at all.

The internal encoding of XML documents is utf-8.
So, as long as you are using some designated parser, simplexml for example, it will recode document to utf-8 and you always have utf-8 output.

the rest depends on what you want to do with this data and what encoding your page in.

Sign up to request clarification or add additional context in comments.

11 Comments

When I don't use utf_encode() on writing on the nodevalue and saving the xml, it swipes everything from the xml leaving only <?xml version="1.0"?> if the string that I want to save has chars as ÅÄÖ...
Please do one thing at a time. Do you have reading sorted out already? there are 2 ways of creating XML, direct one and by using whatever library. if you are using direct method, just like HTML, you can use whatever encoding - just set it up in the header. When using some library writer, you have to supply utf-8 encoded data, so, you may need to recode it.
$xpath->nodeValue = utf8_encode($_POST['input']) this works on writing, but on reading I've got only echo $xpath->nodeValue and if the element I want to read has Å, Ö or Ä it echoes something like "Ääliö"
what is your HTML page encoding? Do you have an idea of what encoding your site in?
I've got a form page which has no meta tags to define the encoding and the php page is just in <?php ... ?>
|
0

Use XMLReader and XMLWriter classes, specifying the input and output encodings when you open the file. In your case, to read the document:

$xmlReader = new XMLReader();
$xmlReader->open('test.xml', 'ISO-8859-15');

Values are then converted to UTF-8 automatically when you retrieve them from the document.

Remember that XMLWriter expects UTF-8 input.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.