473,778 Members | 1,913 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[DOM XML] How to encode a node content (Accentuated characters)

Hello,

I'm trying to generate a RSS newsfeed using the DOM XML functions. However I
can't find a way to use accentuated characters. I even tried to specify a
character encoding set but it doesn't solve the problem.

Error I get :
XML Parsing Error: not well-formed
Location: news.php?action =syndicate&form at=rss2
Line Number 1, Column 102:<?xml version="1.0" encoding="ISO-8859-15"?><rss
version="2.0">< channel><title> Website title - News (
----------------------------------------------------------------------------
-----------------------------------------------------------^

The not well-formed character is an accentuated character, as you can see on
the following code sample :

<?php

header ('content-type: text/xml');

echo ('<?xml version="1.0" encoding="ISO-8859-15"?>');

$dom_doc = domxml_new_doc ('1.0');

$rss_el = $dom_doc->create_eleme nt ('rss');
$rss_el->set_attribut e ('version', '2.0');
$rss_el = $dom_doc->append_child ($rss_el);

$channel_el = $dom_doc->create_eleme nt ('channel');
$channel_el = $rss_el->append_child ($channel_el);

$title_el = $dom_doc->create_eleme nt ('title');
$title_el = $channel_el->append_child ($title_el);
$title_el->set_content ('Website title - News (àéèù)');

echo ($dom_doc->html_dump_me m ());

?>

Removing the accentuated characters from the title generates a well formed
XML file. Note that I also tried to encode the characters using the
htmlentities function but it didn't change anything.

--
Jean-Marc.

Jul 17 '05 #1
6 2957
Jean-Marc Molina <jm******@pasde pourriel-free.fr> wrote:
Error I get :
XML Parsing Error: not well-formed
Location: news.php?action =syndicate&form at=rss2
Line Number 1, Column 102:<?xml version="1.0" encoding="ISO-8859-15"?><rss
version="2.0">< channel><title> Website title - News (
----------------------------------------------------------------------------
-----------------------------------------------------------^

The not well-formed character is an accentuated character, as you can see on
the following code sample : .... $title_el->set_content ('Website title - News (????)'); .... Removing the accentuated characters from the title generates a well formed
XML file. Note that I also tried to encode the characters using the
htmlentities function but it didn't change anything.


Disclaimer: I haven't ever used xmldomdoc in php.

If you are trying to create wellformed XML you should use UTF8 as the
encoding, since that is about the only encoding that XML utils must
support. That is also your problem, your xml doc. is in UTF8 since you
haven't told anyone otherwise (and I can't find how to do that in the
domxml reference).

htmlenties doesn't work either because there are only 5 xmlentities by
default: &amp; &apos; &quot; &gt; &lt;

IMHO the best solution would be to translate you string to UTF8:
http://nl.php.net/manual/en/function...t-encoding.php

(be sure to tell it's iso-8859-15 or else the EUR symbol will get
dropped for the generic currency symbol).

Or use http://nl.php.net/manual/en/function.utf8-encode.php after
manually encoding EUR.

--

Daniel Tryba

Jul 17 '05 #2
Daniel Tryba a écrit/wrote :
htmlenties doesn't work either because there are only 5 xmlentities by
default: &amp; &apos; &quot; &gt; &lt;
I didn't know that. I solved my problem by calling htmlentities 2 times, to
remove the junk :).
IMHO the best solution would be to translate you string to UTF8:
http://nl.php.net/manual/en/function...t-encoding.php


That's an other solution, a better one, thanks !

<?php

....
$title = mb_convert_enco ding (stripslashes ($newsitem ['title']), 'UTF-8',
'ISO-8859-15');
....

?>

From ISO-8859-15 to UTF-8.

--
Jean-Marc.

Jul 17 '05 #3
Daniel Tryba a écrit/wrote :
If you are trying to create wellformed XML you should use UTF8 as the
encoding, since that is about the only encoding that XML utils must
support. That is also your problem, your xml doc. is in UTF8 since you
haven't told anyone otherwise (and I can't find how to do that in the
domxml reference).


Do you know of any good UTF-8 coding editor ? I develop using HTML-Kit and
jEdit but they don't support UTF-8 editing. However I'm not sure application
servers can handle UTF-8 scripts. Can they ?

Thanks again for all your help.

--
Jean-Marc.

Jul 17 '05 #4
Jean-Marc Molina <jm******@pasde pourriel-free.fr> wrote:
Do you know of any good UTF-8 coding editor ?
I never ever use anything other than ASCII :)
I develop using HTML-Kit and
jEdit but they don't support UTF-8 editing. However I'm not sure application
servers can handle UTF-8 scripts. Can they ?


Don't know about htmlkit. jedit is Java, which uses UCS-2 internally,
which is what UTF-8 encapsulates... loading and saving utf8 data should
not be any problem IMHO.

--

Daniel Tryba

Jul 17 '05 #5
Jean-Marc Molina <jm******@pasde pourriel-free.fr> wrote:
However I'm not sure application servers can handle UTF-8 scripts. Can
they ?


Forgot to answer this one.

http://nl.php.net/mb-string should make it possible to use various
encodings. mbstring.intern al_encoding and mbstring.script _encoding
should be the keysettings...

--

Daniel Tryba

Jul 17 '05 #6
Daniel Tryba <Daniel Tryba <ne************ ****@canopus.nl >> wrote:
htmlenties doesn't work either because there are only 5 xmlentities by
default: &amp; &apos; &quot; &gt; &lt;

However, you can still use numerical entities: &#...;

--
Simon Stienen <http://dangerouscat.ne t> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle
Jul 17 '05 #7

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

Similar topics

2
2546
by: Jamais-Content | last post by:
Hi, I currently use the DOM from PHP5 to create XHTML documents. I have a problem with entities. I would like to create a node : <input id="place" value="café rouge"> To do that I simply create the node with createElement, and then : $node -> setAttribute ("value", $val); If I set $val = "café rouge", the saveXML causes PHP to fail with an error message. The accentuated character seems to be a problem. If I set $val = "caf&eacute;...
2
2234
by: DaRik | last post by:
Hi, I'm having some difficulties with a menu I'm making. I build up the menu through DOM. I append childnodes to a tree. 2 types of children are possible: url (a hyperlink) and sub (a submap). The tree is thus of a structure main |-url1
4
1418
by: Steve Jorgensen | last post by:
A while ago, I posted a 1/2 formed idea for what was probably an overcomplicated scheme for improving how we create content using the DOM API. Since then, I've been refactoring some real-world code that builds content with DOM, and have come up with a much simpler, more practical idea that I've had success in implementing. The problem in a nutshell is that, to build a tree or fragment in the DOM, it's just about impossible to arrange the...
8
4286
by: jog | last post by:
Hi, I want to get text out of some nodes of a huge xml file (1,5 GB). The architecture of the xml file is something like this <parent> <page> <title>bla</title> <id></id> <revision> <id></id> <text>blablabla</text>
2
3070
by: jimmyfishbean | last post by:
Hi, I am using VB6, SAX (implementing IVBSAXContentHandler). I need to extract binary encoded data (images) from large XML files and decode this data and generate the appropriate images onto disk. My XML files have the following structure: <?xml version="1.0" encoding="utf-8" ?> <imagepla xmlns:dt="urn:schemas-microsoft-com:datatypes">
8
2294
by: bennett.matthew | last post by:
Hello all, This is probably an elementary (no pun intended) question, but I've spent all afternoon on it and it's driving me crazy. I have a function which dynamically adds to a table. It receives a variable which basically encapsulates this: <div id="tableid"> <tr>
1
10737
by: Rebecca Tsukalas | last post by:
Hello, I have a problem concerning removeChild. This is the XML structure I use with php: <xml_thing <language1 <site>bla1</site <site>bla2</site <site>bla3</site </language1
0
5576
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
10
2230
by: Simon Willison | last post by:
I'm having a horrible time trying to get xml.dom.pulldom to consume a UTF8 encoded XML file. Here's what I've tried so far: <msg>Simon\xe2\x80\x99s XML nightmare</msg> """ ('START_DOCUMENT', <xml.dom.minidom.Document instance at 0x6f06c0>) ('START_ELEMENT', <DOM Element: msg at 0x6f0710>) .... UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 21: ordinal not in range(128)
0
9629
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9465
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10296
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7474
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6723
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5370
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.