473,785 Members | 2,434 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get € past a XML parser

I'm having troubles getting the euro sign through an XML parser.

With the following test code:
<?php
$string = "<root><tes t>€</test></root>";

$parser = xml_parser_crea te();
xml_set_charact er_data_handler ( $parser, 'cdata' );
xml_set_element _handler( $parser, 'starthandler', 'endhandler' );

if( !xml_parse( $parser, $string ) ) {
print xml_error_strin g( xml_get_error_c ode( $parser ));
}

function cdata( $p, $data ) {
print $data."\n";
}

function starthandler( $p, $tag, $att ) {
// print $tag."\n";
}

function endhandler( $p, $tag ) {
// print $tag."\n";
}
?>

I get the following result for $string
$string = "<root><tes t>€</test></root>";
?
$string = "<root><test>&# x20AC;</test></root>";
?
$string = "<root><test>&e uro;</test></root>";
Undeclared entity error

Any solutions to this problem?

Rutger Claes
--
Rutger Claes rg*@rgc.tld
Replace tld with top level domain of belgium to contact me pgp:0x3B7D6BD6
Do not reply to the from address. It's read by /dev/null and sa-learn only

Jul 17 '05 #1
5 4995
>> $string = "<root><tes t>€</test></root>";
It should be
$string = "<root><test>&a mp;#8364;</test></root>";

You have to remember to use the translated &amp; in xml for &

HTH
Ron Chaplin
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
T73 Software & Design
www.t73-softdesign.com
To provide custom and quality
software, designs and services,
to our customers, at an affordable rate,
with minimal delay.

Jul 17 '05 #2
Hello,

on 01/07/2005 11:05 AM Rutger Claes said the following:
I'm having troubles getting the euro sign through an XML parser.

With the following test code:
<?php
$string = "<root><tes t>€</test></root>";


You need to explicitly declare that the output encoding is UTF-8 because
ISO-8859-1 only comprises 8 bit latin characters. Iso-8859-15 would be
the correct encoding but I don't think Expat supports any encoding
besides UTF-8 or ISO-8859-1.

--

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 #3
ro***********@g mail.com wrote:
$string = "<root><tes t>€</test></root>";
It should be
$string = "<root><test>&a mp;#8364;</test></root>";

You have to remember to use the translated &amp; in xml for &

But you don't use entities inside entities I think
HTH
Ron Chaplin
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
T73 Software & Design
www.t73-softdesign.com
To provide custom and quality
software, designs and services,
to our customers, at an affordable rate,
with minimal delay.


--
Rutger Claes rg*@rgc.tld
Replace tld with top level domain of belgium to contact me pgp:0x3B7D6BD6
Do not reply to the from address. It's read by /dev/null and sa-learn only

Jul 17 '05 #4
Manuel Lemos wrote:
Hello,

on 01/07/2005 11:05 AM Rutger Claes said the following:
I'm having troubles getting the euro sign through an XML parser.

With the following test code:
<?php
$string = "<root><tes t>€</test></root>";


You need to explicitly declare that the output encoding is UTF-8 because
ISO-8859-1 only comprises 8 bit latin characters. Iso-8859-15 would be
the correct encoding but I don't think Expat supports any encoding
besides UTF-8 or ISO-8859-1.


You're right. When I enforce UTF-8 on my xml from the time it get's out of
the DOM Object through the SAX parser and Tidy I get some wrong symbols:
â,¬. But when I tell my browser (Konqueror) to use charset UTF-8, it works.

The problem now is that even though I have a
<meta .... content-type: text/hml; charset=UTF-8" /> and a headers( '...
charset=UTF-8' ) the browser still doesn't pick it up when it is set to
auto charset. I've tried mozilla firefox too, same result.

So now I have a working charset, but nobody will see it. Is there a way to
fix this?

Thanks for the answer,
Rutger Claes
--
Rutger Claes rg*@rgc.tld
Replace tld with top level domain of belgium to contact me pgp:0x3B7D6BD6
Do not reply to the from address. It's read by /dev/null and sa-learn only

Jul 17 '05 #5
Rutger Claes wrote:
Manuel Lemos wrote:
Hello,

on 01/07/2005 11:05 AM Rutger Claes said the following:
I'm having troubles getting the euro sign through an XML parser.

With the following test code:
<?php
$string = "<root><tes t>€</test></root>";
You need to explicitly declare that the output encoding is UTF-8 because
ISO-8859-1 only comprises 8 bit latin characters. Iso-8859-15 would be
the correct encoding but I don't think Expat supports any encoding
besides UTF-8 or ISO-8859-1.


You're right. When I enforce UTF-8 on my xml from the time it get's out
of the DOM Object through the SAX parser and Tidy I get some wrong
symbols:
â,¬. But when I tell my browser (Konqueror) to use charset UTF-8, it
works.

The problem now is that even though I have a
<meta .... content-type: text/hml; charset=UTF-8" /> and a headers( '...
charset=UTF-8' ) the browser still doesn't pick it up when it is set to
auto charset. I've tried mozilla firefox too, same result.

So now I have a working charset, but nobody will see it. Is there a way
to fix this?


Fixed that too.
It works now!
Thanks for the answer,
Rutger Claes


--
Rutger Claes rg*@rgc.tld
Replace tld with top level domain of belgium to contact me pgp:0x3B7D6BD6
Do not reply to the from address. It's read by /dev/null and sa-learn only

Jul 17 '05 #6

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

Similar topics

3
6007
by: wenke | last post by:
Hi, I am using the following code (see below) from php.net (http://www.php.net/manual/en/ref.xml.php, example 1) to parse an XML file (encoded in UTF-8). I changed the code slightly so that the cdata sections will be echoed an not the element names as in the original example. In the cdata sections of my XML file I have terms like this:
6
8594
by: J. Baute | last post by:
I'm doing some tests to see if the Session.LCID can be used to easily change a user-dependant locale for number & date/time formatting in ASP. As far as I get the theory this should work, but I'm concerded that there might be some issues when serverside regional settings are changed. I'm having this one case where I'm having something odd already. This is my testcode: <% session.lcid = 2067 ' nl-be
1
4272
by: Marco W | last post by:
Hi, <xsl:value-of select="translate(current(),'€','EUR')" /> only replace the euro sign with 'E' and not 'EUR'. How can I replace the euro sign in the string 'EUR'?
5
6760
by: Lars | last post by:
Why doesn't the W3C's HTML Validator recognize &euro; and what do I have to do to make my html-file valid?
8
8399
by: Kim Bundgaard | last post by:
Hi Anyone know where I can look for problem with codepage conversion between DB2 UDB Connect EE V8.2 (fixpak 3) and DB2 UDB z/OS V7. With DB2 UDB Connect EE V7.2 (fixpak 7) i get Ebcdic X'5A' converted to Ascii X'A4', but with V8 I get it converted to Ascii X'80'. I use Ebcdic codepage/ccsid 277 and client codepage 1252. It looks like a problem with Windows Latin-1 1252/5348 - the Euro codepage,
4
2388
by: Cadderly | last post by:
Hi all, I have the following pseudo-c-code which parse a command line, and puts the command and its arguments in an array, and I can't figure out where/how I should use free: main(void): char ** command_arr; parser(command_arr);
1
1379
by: geoffblanduk_nospam | last post by:
Does anyone know of any classes that will load the XML documentation into some useful classes? I'm assuming there must be some somewhere as that's what the Object browser does to show summaries and comments, and Intellisense must do something similar. But I can't find anything specific in the help files. I could roll my own but would prefer to save an hour or two if it's
1
1413
by: Agnes | last post by:
it is very strange that " i place some code in my Page1's textbox validated event'. then I cut the textbox and paste into page2. I found that , the validated event is change. From Private Sub txtJobNo_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtJobNo.Validated change into Private Sub txtJobNo_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs)
2
1143
by: Agnes | last post by:
In my form, i got around 20 textbox and buttons, Now,i need to move them into the group box. I use 'copy & paste' after doing that, I found that the handles "button.clicked, checkbox.checked'.. All handlers are removed. Can I disable this behavior in Visial Studio ??, in the coming days, I need to move around 10 forms.. Once I move them, I need to double check the event handlers. I am afraid I will miss it . Thanks
0
9645
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
9480
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
10325
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
10091
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7499
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
6739
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();...
1
4050
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
3645
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.