tags:

views:

35

answers:

2

I was reading up about DOM and I saw this function DOMCharacterData::appendData. It appends the string data to the character data. So in layman's terms, what is character data?

+1  A: 

Character data is plain, simple text. Things such as DOMText and DOMComment inherit from DOMCharacterData because they contain text data.

Matti Virkkunen
I'm going to have to give the best answer to Nick for his example. Nothing personal, but I upvoted your answer as well.
Doug
+3  A: 

It is defined in non layman's terms in the standard here.

But more simply, character data is any text in the HTML, that isn't part of a tag. This is in contrast to tags, attributes etc. It can be just typed as text, or defined with a CDATA section in the html, or a comment etc.

Example html:

<tag attribute="value">This is character data</tag>
<a><![CDATA[This is also all character data]]></a>
<!-- even this comment is character data -->

In the code above "This is all character data" is character data, but the tag surrounding it isn't. The same goes for the CDATA section and the comment. One thing that often surprises people is that whitespace counts as character data.

Nick Fortescue
For example, is `<a href="stackoverflow.com">SO</a>` character data? or only the SO part?
Doug
@Doug: Only the SO part.
Matti Virkkunen
Thanks Matti :)
Doug
@Doug - well, `<a href="http://stackoverflow.com">SO</a>` has the potential to be character data, but usually isn't. That's what the CDATA bit is for: `<![CDATA[<a href="http://stackoverflow.com">SO</a>]]>`
Matchu