I am creating a left navigation system utilizing xml and xsl. Everything was been going great until I tried to use a special character in my xml document. I am using »
and I get th error.
reason: Reference to undefined entity 'raquo'.
error code: -1072898046
How do I make this work?
simply replace your HTML entity
»
with the numeric reference»
which is good in any XML and HTML.Joe
When I use the unicode version shows a square.
Putting the entity decalration into the xml doc produces a "Cannot have a DTD declaration outside of a DTD." error. I suppose this is expected.
When I use '' to include the dtd externally it doesn't seem to have any effect.
I am wondering if this is maybe a server issue. I am developing this locally and using Baby Web Server.
You are trying to use an HTML entity in a non-HTML or non-XHTML document. These entities are declared in the document's Document Type Definition (DTD).
You should use the numerical Unicode version of the entity reference. For example, in the case of
»
you should use»
Alternatively, you can define them in your XML document's DTD:
Otherwise, if your document is UTF-8, I believe you can just use the actual character directly in your XML document.
You don't need to declare an entity in your DTD, or even use a DTD. You probably don't need to use the Unicode representation of the character. You certainly don't need to use a CDATA section.
What you need to do is use a DOM to build your XML instead of trying to build it with string manipulation. The DOM will fix this problem for you.
In C#, this code:
produces this output:
As you can see from the first example, the » character is perfectly legal in XML text. But I don't think you're trying to represent that character.
I think you're trying to do what's in the second example, based on the error message that you reported. You're trying to represent the string of characters
»
. The proper way to represent that string of characters in XML text is by escaping the ampersand; thus:»
.So if you must use string manipulation to build your XML, just make sure that you escape any ampersands in your source data. Not to belabor the point, but if you were using a DOM, this would have been done for you automatically.
One other thing. It's quite likely that in your original question, which now reads "I am using »", what you actually typed is "I am using »". The actual post doesn't look like that, though. If you need to represent text literally in markdown, enclose it in backticks; otherwise, HTML entities will get converted to their character representation when the post is rendered.
If you want the output document to contain the named HTML entity
»
rather than the numeric reference, add the following elements to your stylesheet (XSLT2.0 only):did you specify a doc type for your file ?
I think you might get such errors if you forget to specify it.
Also sometimes the entities work if you specify them by number instead of name.