Exam Prep Questions

Team-Fly    

Developing XML Web Services and Server Components with Visual C#™ .NET and the .NET Framework, Exam Cram™ 2 (Exam 70-320)
By Amit Kalani, Priti Kalani

Table of Contents
Chapter 3.  Accessing and Manipulating XML Data


Question 1

You are retrieving customer data from a SQL Server database into an XML document. You want the CustomerName and ContactName columns to be translated into XML elements. Which clause should you use in your SQL statement?

  • A. FOR XML EXPLICIT

  • B. FOR XML AUTO, XMLDATA

  • C. FOR XML AUTO

  • D. FOR XML RAW

A1:

Answer A is correct. Only EXPLICIT mode can map a column to an element. Answers B and C are incorrect because the AUTO mode of the FOR XML clause maps columns to attributes rather than elements, unless you include the ELEMENTS modifier. Answer D is incorrect because the RAW mode of the FOR XML clause also maps columns to attributes.

Question 2

You use a SqlDataAdapter object to fill a DataSet object with the contents of the Customers table in your database. The CompanyName of the first customer is Biggs Industries. You synchronize an XmlDataDocument object with the DataSet object. In the DataSet object, you change the CompanyName of the first customer to Biggs Limited. After that, in the XmlDataDocument, you change the value of the corresponding node to Biggs Co. When you call the Update() method of the SqlDataAdapter object, what is the effect?

  • A. The CompanyName in the database is changed to Biggs Co.

  • B. The CompanyName in the database remains Biggs Industries.

  • C. The CompanyName in the database is changed to Biggs Limited.

  • D. A record-locking error is thrown.

A2:

Answer A is correct. The DataSet and the XmlDataDocument objects represent two different views of the same data structure. Answers B, C, and D are incorrect because the last change made to either view is the change that is written back to the database.

Question 3

You are designing an application that will enable the user to explore the structure of an XML file. You need to allow the user to move to the parent node, the next node, or the first child node from the current node. Which object should you use to implement this requirement?

  • A. XmlReader

  • B. XmlTextReader

  • C. XPathExpression

  • D. XPathNavigator

A3:

Answer D is correct. The XPathNavigator object provides random access movement within the DOM. Answers A and B are incorrect because the XmlReader and XmlTextReader objects provide forward-only movement. Answer C is incorrect because the XPathExpression object is useful for retrieving a set of nodes but not for navigating between nodes.

Question 4

Your application allows the user to perform arbitrary XPath queries on an XML document. The user does not need to be able to alter the document. Which approach will give you the maximum performance for these requirements?

  • A. Read the document into an XmlDocument object. Use the CreateNavigator() method of the XmlDocument object to return an XPathNavigator object. Perform your queries by using the XPathNavigator object.

  • B. Read the document into an XPathDocument object. Use the CreateNavigator() method of the XPathDocument object to return an XPathNavigator object. Perform your queries by using the XPathNavigator object.

  • C. Read the document into an XmlDataDocument object. Use the DataSet property of the XmlDataDocument object to return a DataSet object. Perform your queries by using the DataSet object.

  • D. Read the document into an XmlDataDocument object. Use the CreateNavigator() method of the XmlDataDocument object to return an XPathNavigator object. Perform your queries by using the XPathNavigator object.

A4:

Answer B is correct. The XPathDocument class is optimized for read-only XPath queries. Answers A, C, and D are incorrect because the XmlDocument and the XmlDataDocument objects are not as optimized as XPathDocument for read-only XPath queries.

Question 5

Your application contains an XML file, Orders.xml, with the following content:

 <?xml version="1.0" encoding="utf-8" ?> <Orders>   <Order Order>     <OrderDate>1/1/2003</OrderDate>   </Order>   <Order Order>     <OrderDate>1/2/2003</OrderDate>   </Order>   <Order Order>     <OrderDate>1/3/2003</OrderDate>   </Order> </Orders> 

Your application also contains a form with a Button control named btnProcess and a ListBox control named lbNodes. The Click event handler for the Button control has this code:

 private void btnProcess_Click(     object sender, System.EventArgs e) {     XmlTextReader xtr = new         XmlTextReader(@"..\..\Orders.xml");     while(xtr.Read())     {         if ((xtr.NodeType == XmlNodeType.Attribute)         || (xtr.NodeType ==  XmlNodeType.Element)         || (xtr.NodeType ==  XmlNodeType.Text))         {             if(xtr.HasValue)               lbNodes.Items.Add(xtr.Value);         }     }     xtr.Close(); } 

What will be the contents of the ListBox control after you click the button?

  • A.

     1 1/1/2003 2 1/2/2003 3 1/3/2003 
  • B.

     Orders Order 1/1/2003 Order 1/2/2003 Order 1/3/2003 
  • C.

     1/1/2003 1/2/2003 1/3/2003 
  • D.

     1 2 3 
A5:

Answer C is correct. When you read XML data with the help of XmlReader or its derived classes, nodes are not included for XML attributes, but only for XML elements and the text that they contain. XML element nodes do not have a value. Answers A, B, and D are incorrect because the only text that will be printed is the value of the text nodes within the OrderDate elements.

Question 6

Which of these operations can be carried out in a SQL Server database by sending a properly formatted DiffGram to the database? (Select two.)

  • A. Adding a primary key to a table

  • B. Deleting a row from a table

  • C. Adding a row to a table

  • D. Changing the data type of a column

A6:

Answers B and C are correct. You can add, delete, and update rows of data by using DiffGrams. Answers A and D are incorrect because DiffGrams are not useful for performing manipulation to the database's schema.

Question 7

Which of these operations requires you to have an XML Schema file?

  • A. Validating an XML file with the XmlValidatingReader class

  • B. Updating a SQL Server database with a DiffGram through the SQLXML Managed Classes

  • C. Performing an XPath query with the XPathNavigator class

  • D. Reading an XML file with the XmlTextReader class

A7:

Answer B is correct. You cannot perform a DiffGram update without a schema file that specifies the mapping between XML elements and database columns. Answer A is incorrect because validation can be performed with a DTD or XDR file instead of a schema. Answers C and D are incorrect because performing XPath queries and reading XML files do not require a schema.

Question 8

Your application contains the following code, which uses the SQLXML Managed Classes to apply a DiffGram to a SQL Server database:

 private void btnUpdate_Click(     object sender, System.EventArgs e) {     // Connect to the SQL Server database     SqlXmlCommand sxc = new SqlXmlCommand(      @"Provider=SQLOLEDB; Server=(local)\NetSDK;" +      "database=Northwind; "Integrated Security=SSPI");     // Set up the DiffGram     sxc.CommandType = SqlXmlCommandType.DiffGram;     FileStream fs =      new FileStream(@"..\..\diffgram.xml",         FileMode.Open);     sxc.CommandStream = fs;     // And execute it     sxc.ExecuteNonQuery();     MessageBox.Show("Database was updated!"); } 

When you run the code, it does not update the database. The DiffGram is properly formatted. What should you do to correct this problem?

  • A. Supply an appropriate schema-mapping file for the DiffGram.

  • B. Use a SqlCommand object in place of the SqlXmlCommand object.

  • C. Store the text of the DiffGram in the CommandText property of the SqlXmlCommand object.

  • D. Use a SqlConnection object to make the initial connection to the database.

A8:

Answer A is correct. When executing a DiffGram via the SQLXML Managed Classes, you must supply a mapping schema file. Otherwise, the code doesn't know which elements in the DiffGram map to which columns in the database. Answer B is incorrect because you need to execute a DiffGram instead of an ad-hoc query or a stored procedure. Answer C is incorrect because the CommandText property is not useful when the CommandType property is set to SqlXmlCommandType.DiffGram. Answer D is incorrect because even the SqlXmlCommand object is capable of accepting the connection information.

Question 9

You are developing code that uses the XPathNavigator object to navigate among the nodes in the DOM representation of an XML document. The current node of the XPathNavigator is an element in the XML document that does not have any attributes or any children. You call the MoveToFirstChild() method of the XPathNavigator object. What is the result?

  • A. The next sibling of the current node becomes the current node, and there is no error.

  • B. The next sibling of the current node becomes the current node, and a runtime error is thrown.

  • C. The current node remains unchanged, and there is no error.

  • D. The current node remains unchanged, and a runtime error is thrown.

A9:

Answer C is correct. If the requested move cannot be performed, the current node remains unchanged and the method returns false. Answers A, B, and D are incorrect because the MoveTo methods of the XPathNavigator object always execute without error.

Question 10

Your application contains the following code:

 private void btnReadXML_Click(     object sender, System.EventArgs e) {     // Create a command to retrieve XML     SqlCommand sc =         SqlConnection1.CreateCommand();     sc.CommandType = SqlCommandType.Text;     sc.CommandText =       "SELECT Customers.CustomerID, " +       "Customers.CompanyName," +       "Orders.OrderID, Orders.OrderDate " +       "FROM Customers INNER JOIN Orders " +       "ON Customers.CustomerID = " +       "Orders.CustomerID "       + "WHERE Country = 'Brazil' AND " +       "OrderDate BETWEEN '1997-03-15' " +       "AND '1997-04-15' " +       "FOR XML AUTO, ELEMENTS";     // Read the XML into an XmlReader     XmlReader xr = sc.ExecuteXmlReader();     XmlDocument xd = new XmlDocument();     xd.Load(xr); } 

When you run this code, you receive an error on the line of code that attempts to load the XmlDocument. What can you do to fix the problem?

  • A. Use FOR XML RAW instead of FOR XML AUTO in the SQL statement.

  • B. Replace the XmlDocument object with an XmlDataDocument object.

  • C. Replace the XmlReader object with an XmlTextReader object.

  • D. Replace the SqlCommand object with a SqlXmlCommand object.

Answer D is correct. To load a complete and valid XML document, you need to use the SqlXmlCommand object (from the SQLXML Managed Classes). Answers A, B, and C are incorrect because the SqlCommand.ExecuteXmlReader() method returns an XML fragment rather than an XML document.


    Team-Fly    
    Top


    MCAD Developing XML Web Services and Server Components with Visual C#. NET and the. NET Framework Exam Cram 2 (Exam Cram 70-320)
    Managing Globally with Information Technology
    ISBN: 789728974
    EAN: 2147483647
    Year: 2002
    Pages: 179

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