Review Questions

1. 

XML data files must follow some simple rules in order to be called “well formed” and to be used by standard XML parsers. Which one of these choices is not one of the rules?

  1. Each file must have a uniquely named root element.

  2. Element tag names and attribute names are case sensitive.

  3. Only element tag names that are defined in the schema can be used.

  4. Each opening tag must have a matching closing tag.

ca uniquely named root element, case sensitivity, and matching opening and closing tags are some the rules that define a well-formed xml data file. the third choice is incorrect because validation against a schema is a separate step beyond the rules for well-formed xml.

2. 

Several technologies have been developed for validating the contents of XML files against a defined set of element and attribute names and other formatting specifics. Which of these is the most up-to-date technology?

  1. XDR

  2. XSD

  3. DTD

  4. XSLT

bdtd was the original means for validating xml data.xdr was an interim technology, mostly used on the microsoft platform before the w3c finalized xsd. xslt is used for creating stylesheets for formatting xml data; it does not perform validation.

3. 

You are creating an application that loads data from XML data files into a DataSet. The XML data file contains several items that you do not want to load for this particular application. How can you most easily accomplish this?

  1. You will have to write custom DOM code to remove the data that you do not want.

  2. You will have to use XSLT to transform the data file to the new format.

  3. Read the schema file into the data that establishes your desired data format. Read in the XML data with the XmlReadMode parameter set to InferSchema.

  4. Read the schema file into the data that establishes your desired data format. Read in the XML data with the XmlReadMode parameter set to IgnoreSchema.

dthe first two choices could be used to create the desired result, but either option would result in writing a considerable amount of code. the last option is correct because the ignoreschema parameter will not load any data from the source file that doesn t match the current dataset schema. using the inferschema parameter will cause all the data items to be loaded and will change the schema to include the new data as well.

4. 

You would like to output a copy of the current DataSet schema to a disk file, to use for performing validation in another part of your application. How can you quickly accomplish this?

  1. myDataSet.WriteXml(filename, XmlWriteMode.WriteSchema)

  2. myDataSet.GetXmlSchema()

  3. myDataSet.WriteXmlSchema(filename)

  4. myDataSet.InferXmlSchema(filename)

cthe third option is correct because this produces a disk file with only the schema information. the first option would produce a disk file with both an in-line schema and the data. the second option returns the schema information as a string, so additional programming would be required to save the information to a disk file. the last option is used to input schema information into a dataset .

5. 

You would like to create XML output from your DataSet. When you call the WriteXml method, the resulting XML output looks like this:

<jobs>     <id><1/id>     <job_desc>New Hire - Job not specified</job_desc>     <min_lvl>10</min_lvl>     <max_lvl>50</max_lvl>   </jobs>

The application that will be consuming your data requires this format:

<jobs  description="Chief Executive Officer"        min="200" max="225" />

How can you create this output?

  1. Set the DataSet.ColumnMapping property to Element.

  2. Set the DataSet.ColumnMapping property to Attribute.

  3. Set each DataColumn.ColumnMapping property to Element.

  4. Set each DataColumn.ColumnMapping property to Attribute.

dthe columnmapping property of each datacolumn determines whether the value for that column is output as an xml element or attribute. the dataset class does not have a columnmapping property.

6. 

After allowing your user to edit the data in a DataSet, you would like to pass an XML file to a business logic component for verification. The verification logic requires that records changed by the user are easily identifiable, and that any user changes that violate business rules must be reset to the original value. Which feature of the ADO.NET DataSet enables you to capture this information in an XML document?

  1. DiffGram.

  2. UpdateGram.

  3. You must clone the DataSet before the user makes any changes.

  4. You must copy the DataSet before the user makes any changes.

a diffgram is correct. diffgram output adds a haschanges attribute to any modified, inserted, or deleted rows. the original values of the data are in a separate - diffgr:before - section of the xml output. updategrams are used to send updates to sql server 2000 in the form of xml data files. the dataset copy method would retain a record of the original values, but would require more coding to compare the two versions. the dataset clone method copies only the structure of the dataset , not data.

7. 

Which statement best describes the way that an XmlTextReader works?

  1. The XmlTextReader enables you to load an XML data file in memory and have complete programmatic access to the data.

  2. The XmlTextReader enables to you to process each node in an XML file sequentially.

  3. The XmlTextReader enables you to work with your XML data as either a relational table or a hierarchical tree of nodes.

  4. The XmlTextReader enables you to convert text files into XML data.

bthe xmltextreader provides forward-only, read-only access to xml data. the xml dom xmldocument provides complete programmatic access to xml data. the xmldatadocument enables youto treat your data as either a relational table or a hierarchical tree of nodes. there is no class that automatically converts text files to xml.

8. 

The XML Document Object Model (DOM) has only three base classes at its core. Which of the following is one of the base classes?

  1. XmlElement

  2. XmlAttribute

  3. XmlNodeList

  4. XmlDocument

cthe base classes of the xml dom are xmlnode , and two collection classes, xmlnodelist and xmlnamednodemap . xmlelement , xmlattribute , and xmldocument (along with many other classes) are derived from the xmlnode base class.

9. 

The XML DOM has two similar methods, SelectNodes and SelectSingleNode. What makes these methods similar?

  1. Both methods return a NodeList collection.

  2. Both methods return a NamedNodeMap collection.

  3. Both methods select nodes based on tag name.

  4. Both methods select nodes based on XPath expressions.

dboth methods use xpath expressions to select matching nodes. selectnodes returns a nodelist collection, and selectsinglenode returns a reference to the first matching node. these methods can include a tag name in the selection criteria but they can evaluate much more sophisticated patterns that match a node s position in the document hierarchy or specific data values.

10. 

You are using XML DOM programming in order to create a new structure of XML nodes in your application code. You have created a root node <employeelist> and an <employee> node. As you create the next set of nodes, you would like each new node to be added as the last child of the <employee> node. Which method should you call?

  1. myElement.InsertBefore(newNode, lastNode)

  2. myElement.InsertAfter(newNode, lastNode)

  3. myElement.AppendChild(childNode)

  4. myElement.PrependChild(childNode)

cthe appendchild method will add the new node as the last child node of the parent ( myelement ). prependchild adds the new element as the first child of the parent. the insertbefore and insertafter methods require you to specify a reference node and do not automatically add the new element as a child of the current node.

11. 

You’re writing a function that processes XML data. The procedures that call your function pass in a Stream object that contains the XML data. Which method should you call to populate and XmlDocument object?

  1. XmlDocument.LoadXml

  2. XmlDocument.Load

  3. XmlDocument.ImportNode

  4. XmlDocument.ReadNode

bthe load method can read data from a disk file or stream object. the loadxml method loads data from a string variable. the importnode method reads information from one xmldocument into another. the readnode method reads node information from the current node of an xmlreader object.

12. 

What is an advantage of learning to use XPath expressions?

  1. XPath expressions are the fastest way to locate data in an XML document.

  2. XPath expression syntax is a common notation that is used by several XML processing technologies.

  3. XPath is the only way to locate nodes in an XML data file.

  4. XPath is a special capability of the .NET Framework classes.

bafter you understand xpath expression syntax, you can use it in xml dom programming, xslt processing, and other xml-related technologies. xpath expression queries can be optimized for performance if you use xpathdocument and compiled xpathexpression objects, but might not always be the fastest method of locating data. other methods are available for locating specific nodes, such as the getelementsbytagname method and using an xmlreader and testing each node for type and name as it is processed. the last option is incorrect because the xpath specification (like most other xml related technologies) is managed by the w3c and is not proprietary to any single software platform.

13. 

Your application must do extensive searching through large XML data files. Which option is likely to give you the best performance?

  1. Use XmlDataDocument objects. If your XPath queries do not work, you can always fall back on SQL queries.

  2. Use an XPathDocument and the SelectNodes method.

  3. Use an XPathDocument and the Compile method.

  4. Use an XmlDocument and the SelectNodes method.

cthe xpathdocument (and also some classes in the system.xml.xsl namespace), are optimized to perform xpath queries. when you compile an xpath expression, repeated searches with the same expression are further optimized. the xpath document does have a selectnodes method. the other options are functional but might not provide the best performance.

14. 

You are developing an application that processes business transactions from many e-commerce trading partners, in the form of XML documents. At what point, or points, in the data flow is it most important to perform XSD schema validation on the data files that you are exchanging with your business partners?

  1. Anytime XML data is read or written by your program code, validation is necessary.

  2. Validation is most important to ensure that your application is sending valid XML data to your business partners.

  3. Validation is most important to ensure that your application is receiving valid XML data from your business partners.

  4. Validation is important only if you notice a large number of errors when the data from XML input files are processed.

cit is most important to validate incoming data files, before you use the information in your own applications or store the information in your database. after you have thoroughly tested your own applications that produce xml output, you should be reasonably sure that the xml output created is in the correct format. because validation requires extra processing overhead, it is not necessary to validate xml data at every step of processing. the last option is incorrect because validation of xml input files will notify you in advance of trying to process them that the data might be invalid.

15. 

You are writing a SQL query to retrieve XML data from Microsoft SQL Server 2000. You would like each column value from the table to be in the form of columnname="value" and you would like the element name to reflect the name of the database table. Which SQL query would you use?

  1. SELECT * FROM table FOR XML AUTO

  2. SELECT * FROM table FOR XML RAW

  3. SELECT * FROM table FOR XML EXPLICIT

  4. SELECT * FROM table FOR XML ELEMENTS

athe first choice is correct because it will create a format of xml output that uses the table name as the element name for each row, and creates an attribute name/value pair for each column name and its data value. the second choice would use the generic - row - element tag name for each data row in the resultset. the third choice creates a custom xml output when a query retrieves data from multiple tables. the last choice is incorrect because it should actually state select * from table for xml auto, elements and this would result in a format of xml with no attributes; columns would be written as child elements of the - table - element.

Answers

1. 

C A uniquely named root element, case sensitivity, and matching opening and closing tags are some the rules that define a well-formed XML data file. The third choice is incorrect because validation against a schema is a separate step beyond the rules for well-formed XML.

2. 

B DTD was the original means for validating XML data. XDR was an interim technology, mostly used on the Microsoft platform before the W3C finalized XSD. XSLT is used for creating stylesheets for formatting XML data; it does not perform validation.

3. 

D The first two choices could be used to create the desired result, but either option would result in writing a considerable amount of code. The last option is correct because the IgnoreSchema parameter will not load any data from the source file that doesn’t match the current DataSet schema. Using the InferSchema parameter will cause all the data items to be loaded and will change the schema to include the new data as well.

4. 

C The third option is correct because this produces a disk file with only the schema information. The first option would produce a disk file with both an in-line schema and the data. The second option returns the schema information as a string, so additional programming would be required to save the information to a disk file. The last option is used to input schema information into a DataSet.

5. 

D The ColumnMapping property of each DataColumn determines whether the value for that column is output as an XML element or attribute. The DataSet class does not have a ColumnMapping property.

6. 

A Diffgram is correct. DiffGram output adds a hasChanges attribute to any modified, inserted, or deleted rows. The original values of the data are in a separate <diffgr:before> section of the XML output. UpdateGrams are used to send updates to SQL Server 2000 in the form of XML data files. The DataSet Copy method would retain a record of the original values, but would require more coding to compare the two versions. The DataSet Clone method copies only the structure of the DataSet, not data.

7. 

B The XmlTextReader provides forward-only, read-only access to XML data. The XML DOM XmlDocument provides complete programmatic access to XML data. The XmlDataDocument enables you to treat your data as either a relational table or a hierarchical tree of nodes. There is no class that automatically converts text files to XML.

8. 

C The base classes of the XML DOM are XmlNode, and two collection classes, XmlNodeList and XmlNamedNodeMap. XmlElement, XmlAttribute, and XmlDocument (along with many other classes) are derived from the XmlNode base class.

9. 

D Both methods use XPath expressions to select matching nodes. SelectNodes returns a NodeList collection, and SelectSingleNode returns a reference to the first matching node. These methods can include a tag name in the selection criteria but they can evaluate much more sophisticated patterns that match a node’s position in the document hierarchy or specific data values.

10. 

C The AppendChild method will add the new node as the last child node of the parent (myElement). PrependChild adds the new element as the first child of the parent. The InsertBefore and InsertAfter methods require you to specify a reference node and do not automatically add the new element as a child of the current node.

11. 

B The Load method can read data from a disk file or Stream object. The LoadXml method loads data from a string variable. The ImportNode method reads information from one XmlDocument into another. The ReadNode method reads node information from the current node of an XmlReader object.

12. 

B After you understand XPath expression syntax, you can use it in XML DOM programming, XSLT processing, and other XML-related technologies. XPath expression queries can be optimized for performance if you use XPathDocument and compiled XPathExpression objects, but might not always be the fastest method of locating data. Other methods are available for locating specific nodes, such as the GetElementsbyTagName method and using an XmlReader and testing each node for type and name as it is processed. The last option is incorrect because the XPath specification (like most other XML related technologies) is managed by the W3C and is not proprietary to any single software platform.

13. 

C The XPathDocument (and also some classes in the System.Xml.Xsl namespace), are optimized to perform XPath queries. When you compile an XPath expression, repeated searches with the same expression are further optimized. The XPath document does have a SelectNodes method. The other options are functional but might not provide the best performance.

14. 

C It is most important to validate incoming data files, before you use the information in your own applications or store the information in your database. After you have thoroughly tested your own applications that produce XML output, you should be reasonably sure that the XML output created is in the correct format. Because validation requires extra processing overhead, it is not necessary to validate XML data at every step of processing. The last option is incorrect because validation of XML input files will notify you in advance of trying to process them that the data might be invalid.

15. 

A The first choice is correct because it will create a format of XML output that uses the table name as the element name for each row, and creates an attribute name/value pair for each column name and its data value. The second choice would use the generic <row> element tag name for each data row in the resultset. The third choice creates a custom XML output when a query retrieves data from multiple tables. The last choice is incorrect because it should actually state SELECT * FROM table FOR XML AUTO, ELEMENTS and this would result in a format of XML with no attributes; columns would be written as child elements of the <table> element.



MCAD/MCSD(c) Visual Basic. NET XML Web Services and Server Components Study Guide
MCAD/MCSD: Visual Basic .NET XML Web Services and Server Components Study Guide
ISBN: 0782141935
EAN: 2147483647
Year: 2005
Pages: 153

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net