0

My browser is telling me:

error on line 2 at column 308899: Entity 'ntilde' not defined

and the specific line is in my xml as:

<LastName>Trevi&ntilde;o</LastName>

the name was originally Treviño, but it was modified via php's htmlentities function.

What can I do to get php and xml to play nicely?


Using Chrome 19 on Mac.

Jacksonkr
  • 31,583
  • 39
  • 180
  • 284

5 Answers5

6

Apparently using htmlspecialchars and htmlentities in tandem does the trick.

htmlspecialchars(htmlentities($value));
Jacksonkr
  • 31,583
  • 39
  • 180
  • 284
1

Are you actually generating XML, or HTML? They're not the same thing. HTML defines a bunch of entities (IIRC) whereas XML has very few "built-in" - just a few like &amp; and &lt;.

Why both using the entity when you can just use the text directly? Simply make sure you're consistent about the encoding you use (UTF-8 would be a good bet).

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
0

You dont need to encode the tilde character in XML. It will throw errors. Best thing to do in this case might be to wrap the text in CDATA.

<LastName><![CDATA[Trevi&ntilde;o]]></LastName>
Darek Rossman
  • 1,323
  • 1
  • 10
  • 12
  • this works, but when I pass that to `SimpleXML`s `addChild` it ruins the `CDATA` by replacing the `<>` with `<>` – Jacksonkr May 31 '12 at 21:39
  • Check out this link about exactly that issue: http://stackoverflow.com/questions/3424084/how-to-keep-domdocument-from-saving-as-lt – Darek Rossman Jun 01 '12 at 12:43
0

Try to specify encoding for htmlentities

htmlentities($string,ENT_QUOTES,'UTF-8');
Pethical
  • 1,472
  • 11
  • 18
0

It should be: Treviño. An Entity may be missing from your DTD file? something like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Customer
[
<!ENTITY ntilde "&#241;">
]>

<Customer>
<LastName>Trevi&ntilde;o</LastName>
</Customer>
75ntamas
  • 123
  • 5