What is meant by 'parsed data' in the xml 1.1 spec?

I am re-wording my question because the 'parsed entity' thing has nothing to do with the problem at hand.

XML 1.1 versus 1.0

Is an xml 1.1 library is to escape illegal characters before serializing/deserializing them? Or is the library is to forbid them outright? Which is the correct way to set Text on an xml element?

if Element e = new Element("foo")

Should I do this:

e.setText(sanitized_text_illegal_characters_removed_or_escaped) ?

or

e.setText(any_text)

Answers


A parsed entity is something you don't really need to worry about unless you're writing an XML parser. It's things like < and &. You can define your own in the document DTD, but it's a rarely used feature. An external parsed entity is one whose contents reside in another file or network resource or somewhere like that.

As to your main question:

Which is the correct way to set Text on an xml element?

if Element e = new Element("foo")

Should I do this:

e.setText(string_of_sanitized_data_with_illegal_characters_escaped) ?

or

e.setText(any_text)

You should set the text as you would like it to come out the other end, when the document is deserialized. This normally means you should not escape the data, and the XML library will do this for you.

e.g.:

  1. You insert the text "bed & breakfast".
  2. The XML library converts this to "bed &amp; breakfast" or "<![CDATA[bed & breakfast]]>" or some other representation, it doesn't really matter.
  3. You send the document somewhere else.
  4. The other parser reads the document and converts the text back.
  5. The end software retrieves the string "bed & breakfast".

If you're writing XML programmatically, then you almost certainly don't want to use parsed entities.

There are two kinds of parsed entities: internal and external. An internal parsed entity is defined by a DTD declaration like this:

<!ENTITY me "Mike">

or

<!ENTITY me "<name>Mike</name>">

An external parsed entity is defined by a DTD declaration like this:

<!ENTITY me SYSTEM "me.xml">

Whether the entity is internal or external, it can be referenced by an entity reference like this:

&me;

which can appear within the content of an element or attribute.


Need Your Help

WPF: How to handle multi-XAML UIs?

c# wpf xaml datagrid

I don't know about you folks, but I suffer from a severe case of Deep Indentation Allergy. I can barely manage all those indented XAML blocks.