Q:

Simple way to do XML with HTML codes?

I have an XML file, sample.xml, that contains the following:
<Tokens>
   <Token>Hello&nbsp;World</Token>
</Tokens>

I want to parse it - but get errors when it gets to the NBSP
I do not have access to the schema for the XML I am using (the one that defines Token or Tokens).
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
doc = docBuilder.parse("sample.xml");

Since I do not have the Schema for my XML document, I was wondering if there is a way to have it completely ignore the HTML special characters while parsing?

A:

In XML, &nbsp; is an entity reference, but an undefined one, unless you provide a definition. You cannot make an XML parser ignore them, but you can define them, e.g. starting your document with
<!DOCTYPE Tokens [<!ENTITY nbsp "&#xa0;">]>

However, this is probably not useful if you are generating the XML file. You might just as well generate a document containing the real character “ ” U+00A0 NO-BREAK SPACE, or the character reference &#xa0; or its decimal equivalent &#160;.
Cf. to question How do I define HTML entity references inside a valid XML document?

