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.

Write a node. S<strong>in</strong>ce the URN associated with// the prefix does not match the specified URN, a new prefix/URN// b<strong>in</strong>d<strong>in</strong>g is generated root<strong>in</strong>g <strong>in</strong> the new node.writer.WriteStartElement(prefix, "value","despos:isbn-0735618011");writer.WriteStr<strong>in</strong>g("...");writer.WriteEndElement();The two nodes created look like the <strong>XML</strong> source code shown here:......The two nodes are scoped <strong>in</strong> different namespaces although they have thesame name and even the same namespace prefix.Qualified AttributesTo write qualified attributes, you use some of the overloads of the WriteAttributeStr<strong>in</strong>gand WriteStartAttribute methods. Accord<strong>in</strong>g to the W3C <strong>XML</strong> 1.0 and Namespacesspecifications, element nodes can have an associated namespace without a prefix, asshown here:...This namespace can be obta<strong>in</strong>ed with the follow<strong>in</strong>g code:writer.WriteStartElement("value", "despos:isbn-0735618011");writer.WriteStr<strong>in</strong>g("...");writer.WriteEndElement();Attributes, on the other hand, can't do without a prefix once they are bound to anamespace. If you don't <strong>in</strong>dicate the prefix explicitly, one is generated automatically.Try the follow<strong>in</strong>g code:writer.WriteStartElement("element");writer.WriteStartAttribute("value", "despos:isbn-0735618011");writer.WriteStr<strong>in</strong>g(s);writer.WriteEndAttribute();writer.WriteEndElement();The value attribute is associated with a namespace URN, but no prefix is set orretrieved through LookupPrefix. The resultant <strong>XML</strong> text is shown here:An automatic prefix is generated to scope the attribute. There are two elements <strong>in</strong> the.<strong>NET</strong> Framework–generated prefix: the depth level, d{n}, and the prefix <strong>in</strong>dex, p{n}. Thedepth level is a one-based value that counts the depth of the node <strong>in</strong> the <strong>XML</strong> tree. Theprefix <strong>in</strong>dex counts the number of namespaces def<strong>in</strong>ed <strong>in</strong> the body of the node. Forexample, consider the follow<strong>in</strong>g code:writer.WriteStartElement("parent");131

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

Saved successfully!

Ooh no, something went wrong!