转载: .net程序员偏向XML开发的面试题
Developers using XML
· What is the purpose of XML Namespaces? XML Namespaces remove conflicts between different documents from different sources.
· When is the DOM appropriate for use? When is it not? Are there size limitations?
Dom is appropriate for small document and the document needs to be modified. It’s not appropriate for big document because of performance issue. There is no size limitation as long as there is enough physical memory.
· What is the one fundamental difference between Elements and Attributes?
Element can contain another elements and attributes. Attributes can only reside inside an element.
· What is the difference between Well-Formed XML and Valid XML?
Well-Formed XML follows xml grammar. Valid XML is validated against xml schema or dtd. A valid xml is well-formed. A well-formed xml might not be valid.
· How would you validate XML using .NET?
Using XmlValidatingReader class.
· Why is this almost always a bad idea? When is it a good idea? myXmlDocument.SelectNodes("//mynode");
This statement returns all elements under mynode. This could return a large amount of data. It’s more efficient to use SelectSingleNode method and pass a full path, or use SelectNodes with a relatively deeper path.
· Describe the difference between pull-style parsers (XmlReader) and eventing-readers (Sax)
In XmlReader you control the parsing and define which element to go to. Sax parses the Xml internally, and raises events whenever it find something interesting.
· What is the difference between XPathDocument and XmlDocument? Describe situations where one should be used over the other.
XpathDocument is not editable. XmlDocument is editable. XpathDocument is used for fast readonly situation. XmlDocument is used when the document needs to be changed.
· What is the difference between an XML "Fragment" and an XML "Document."
XML Fragment is not a full xml document. It doesn’t have element.
· What does it meant to say “the canonical” form of XML?
The purpose of Canonical XML is to define a standard format for an XML document. Canonical XML is a very strict XML syntax, which lets documents in canonical XML be compared directly.
Using this strict syntax makes it easier to see whether two XML documents are the same. For example, a section of text in one document might read Black & White, whereas the same section of text might read Black & White in another document, and even in another. If you compare those three documents byte by byte, they’ll be different. But if you write them all in canonical XML, which specifies every aspect of the syntax you can use, these three documents would all have the same version of this text (which would be Black & White) and could be compared without problem. This Comparison is especially critical when xml documents are digitally signed. The digital signal may be interpreted in different way and the document may be rejected. Why is the XML InfoSet specification different from the Xml DOM? What does the InfoSet attempt to solve?
· Contrast DTDs versus XSDs. What are their similarities and differences? Which is preferred and why?
Both are used for defining the rules of an xml document. DTDs are written in regex, XSDs are written using xml.
Document Type Definition (DTD) describes a model or set of rules for an XML document. XML Schema Definition (XSD) also describes the structure of an XML document but XSDs are much more powerful. The disadvantage with the Document Type Definition is it doesn’t support data types beyond the basic 10 primitive types. It cannot properly define the type of data contained by the tag. An Xml Schema provides an Object Oriented approach to defining the format of an xml document. The Xml schema support most basic programming types like integer, byte, string, float etc., We can also define complex types of our own which can be used to define a xml document. Xml Schemas are always preferred over DTDs as a document can be more precisely defined using the XML Schemas because of its rich support for data representation.
· Does System.Xml support DTDs? How?
Yes, in addition to XDR and XSD schema validation, .NET continues to support the DTD to validate the XML documents. The System.Xml namespace contains a class named XmlValidatingReader that can be used to validate the XML documents.
· Can any XML Schema be represented as an object graph? Vice versa?
Yes.