Which XML output is produced by this code segment?

You are troubleshooting a Visual Studio .NET application that was developed by a former colleague. You find the following code segment within a large assembly:

XmlElement theElement;
XmlElement anotherElement;
XmlDocument doc = new XmlDocument();
XmlDeclaration theDecl =
doc.CreateXmlDeclaration(“1.0”,null,null);
doc.AppendChild(theDecl);
theElement = doc.CreateElement(“Library”);
doc.AppendChild(theElement);
theElement = doc.CreateElement(“Book”);
theElement.SetAttribute(“type”,”Mystery”);
anotherElement = doc.CreateElement(“Title”);
anotherElement.InnerText = “Book Title”;
anotherElement.AppendChild(theElement);
doc.DocumentElement.AppendChild(theElement);

Which XML output is produced by this code segment?

You are troubleshooting a Visual Studio .NET application that was developed by a former colleague. You find the following code segment within a large assembly:

XmlElement theElement;
XmlElement anotherElement;
XmlDocument doc = new XmlDocument();
XmlDeclaration theDecl =
doc.CreateXmlDeclaration(“1.0”,null,null);
doc.AppendChild(theDecl);
theElement = doc.CreateElement(“Library”);
doc.AppendChild(theElement);
theElement = doc.CreateElement(“Book”);
theElement.SetAttribute(“type”,”Mystery”);
anotherElement = doc.CreateElement(“Title”);
anotherElement.InnerText = “Book Title”;
anotherElement.AppendChild(theElement);
doc.DocumentElement.AppendChild(theElement);

Which XML output is produced by this code segment?

A.
<xml version=”1.0″>
<Library />

B.
<xml version=”1.0″>
<Library>
<Book type=”Mystery” />
</Library>

C.
<xml version=”1.0″>
<Library>
<Book type=”Mystery”>
<Title>Book Title</Title>
</Book>
</Library>

D.
<xml version=”1.0″>
<Library>
<Title>Book Title<Book type=”Mystery” /></Title>
</Library>



Leave a Reply 0

Your email address will not be published. Required fields are marked *