13.07.2015 Views

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Table 3-4: Ways to Handle EntitiesActionDescriptionentities as EntityReference nodes. You must then callthe ResolveEntity method to expand a general entity.ExpandEntitiesDefault sett<strong>in</strong>g; expands all entities and replacesthem with their underly<strong>in</strong>g text.A character entity is an <strong>XML</strong> entity that evaluates to a character and is expressedthrough the character's decimal or hexadecimal representation. For example, &#65;expands to A. Character entities are mostly used to guarantee the well-<strong>for</strong>medness ofthe overall document when this is potentially broken by that character.A general entity is a normal <strong>XML</strong> entity that can expand to a str<strong>in</strong>g of any size, <strong>in</strong>clud<strong>in</strong>ga s<strong>in</strong>gle character. A general entity is always expressed through text, even when itrefers to a s<strong>in</strong>gle character.By default, the reader makes no dist<strong>in</strong>ction between the types of entities and expandsthem all when needed. By sett<strong>in</strong>g the EntityHandl<strong>in</strong>g property to ExpandCharEntities,however, you can optimize entity handl<strong>in</strong>g by expand<strong>in</strong>g the general entities only whenrequired. In this case, a call to Read expands only character entities. To expandgeneral entities, you must resort to the ResolveEntity method or to GetAttribute, if theentity is part of an attribute.The EntityHandl<strong>in</strong>g property can be changed on the fly; the new value takes effectwhen the next call to Read is made.A Cache <strong>for</strong> SchemasIn the validat<strong>in</strong>g reader class, the Schemas property represents a collection—that is, an<strong>in</strong>stance of the XmlSchemaCollection class—<strong>in</strong> which you can store one or moreschemas that you plan to use later <strong>for</strong> validation. Us<strong>in</strong>g the schema collection improvesoverall per<strong>for</strong>mance because the various schemas are held <strong>in</strong> memory and don't needto be loaded each and every time validation occurs. You can add as many XSD andXDR schemas as you want, but bear <strong>in</strong> m<strong>in</strong>d that the collection must be completedbe<strong>for</strong>e the first Read call is made.To add a new schema to the cache, you use the Add method of theXmlSchemaCollection object. The method has a few overloads, as follows:public void Add(XmlSchemaCollection);public XmlSchema Add(XmlSchema);public XmlSchema Add(str<strong>in</strong>g, str<strong>in</strong>g);public XmlSchema Add(str<strong>in</strong>g, XmlReader);The first overload populates the current collection with all the schemas def<strong>in</strong>ed <strong>in</strong> thegiven collection. The rema<strong>in</strong><strong>in</strong>g three overloads build from different data and return an<strong>in</strong>stance of the XmlSchema class—the .<strong>NET</strong> Framework class that conta<strong>in</strong>s thedef<strong>in</strong>ition of an XSD schema.Populat<strong>in</strong>g the Schema CollectionThe schema collection actually consists of <strong>in</strong>stances of the XmlSchema class—a k<strong>in</strong>dof compiled version of the schema. The various overloads of the Add method allow youto create an XmlSchema object from a variety of <strong>in</strong>put arguments. For example,consider the follow<strong>in</strong>g method:public XmlSchema Add(str<strong>in</strong>g ns,str<strong>in</strong>g url74

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!