Which code segment should you use?

You use Microsoft .NET Framework 4 to develop an application. You use the XmlReader class to load
XML from a location that you do not control. You need to ensure that loading the XML will not load
external resources that are referenced in the XML. Which code segment should you use?

You use Microsoft .NET Framework 4 to develop an application. You use the XmlReader class to load
XML from a location that you do not control. You need to ensure that loading the XML will not load
external resources that are referenced in the XML. Which code segment should you use?

A.
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.None;
XmlReader reader = XmlReader.Create(“data.xml”, settings);

B.
XmlReaderSettings settings = new XmlReaderSettings();
settings.CheckCharacters = true;
XmlReader reader = XmlReader.Create(“data.xml”, settings);

C.
XmlReaderSettings settings = new XmlReaderSettings();
settings.XmlResolver = null;
XmlReader reader = XmlReader.Create(“data.xml”, settings);

D.
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Auto;
XmlReader reader = XmlReader.Create(“data.xml”, settings);

Explanation:
CheckCharacters Gets or sets a value indicating whether to do character checking.
ConformanceLevel Gets or sets the level of conformance which the XmlReader will comply.
ValidationType Gets or sets a value indicating whether the XmlReader will perform validation or type
assignment when reading.
XmlResolver Sets the XmlResolver used to access external documents.
XmlReaderSettings Class
(http://msdn.microsoft.com/en-us/library/system.xml.xmlreadersettings.aspx)
http://stackoverflow.com/questions/215854/prevent-dtd-download-when-parsing-xml
http://msdn.microsoft.com/en-us/library/x1h1125x.aspx



Leave a Reply 0

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