CHAPTER 2 XML STRUCTURE The entity reference, when used within the document, then is able to take its meaning from the definition. This is further explained in Chapter 3. General Entity Declaration Entity declarations may be either general or parameter entity declarations. Entity declarations will be covered in more depth in Chapter 3, though general entities have some bearing to this discussion with respect to entity references. The common use of general entities is to declare the text replacement value for entity references. General entities are commonly referred to as entities unless used in a context where that name would be ambiguous; therefore, for the sake of this section, entities will refer to general entities. Entities are defined within the DTD, which is part of the prolog. Suppose you had the string “This is replacement text”, which you want to use many times within the document. You could create an entity with a legal name, in this case “replaceit”: ]> &replaceit; If this document were loaded into a parser that was substituting entities, which means it is replacing the entity reference (&replaceit;) with the text string defined in the entity declaration, the results would look something like this: ]> This is replacement text Using Namespaces Documents can become quite complex. They can consist of your own XML as well as XML from outside sources. Element and attribute names can start overlapping, which then makes the names ambiguous. How do you determine whether the name comes from your data or from an outside source? Looking at the document, you would have to guess what the elements and attributes mean depending on the context. Unfortunately, applications processing the XML typically don t understand context, so the document would no longer have the correct meaning. Namespaces solve this potential problem. Namespaces are collections of names identified by URIs. They are not part of the XML specification but have their own specification that applies to XML. Through the use of namespaces, names within a document are able to retain their original meanings even when combined with another document that contains some of the same names with completely different meanings. Assume you are building a document that includes customer information as well as items they have ordered, and assume your customer records look like the following:
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP MySQL Web Hosting services
No comments yet.
Sorry, the comment form is closed at this time.