Dieser Artikel wurde maschinell übersetzt. Wenn Sie die englische Version des Artikels anzeigen möchten, aktivieren Sie das Kontrollkästchen Englisch. Sie können den englischen Text auch in einem Popupfenster anzeigen, indem Sie den Mauszeiger über den Text bewegen.
Übersetzung
Englisch

XmlReaderSettings.ConformanceLevel-Eigenschaft

 

Veröffentlicht: Oktober 2016

Ruft den Konformitätsgrad ab, dem der XmlReader entspricht, oder legt diesen fest.

Namespace:   System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public ConformanceLevel ConformanceLevel { get; set; }

Eigenschaftswert

Type: System.Xml.ConformanceLevel

Einer der Enumerationswerte, der das Übereinstimmungsniveau angibt, den der XML-Reader umsetzt. Die Standardeinstellung ist ConformanceLevel.Document.

XML readers that are created by the Overload:System.Xml.XmlReader.Create method meet the following compliance requirements by default:

  • New lines and attribute value are normalized according to the W3C XML 1.0 Recommendationhttp://www.w3.org/TR/2006/REC-xml-20060816/.

  • All entities are automatically expanded.

  • Default attributes declared in the document type definition are always added even when the reader does not validate.

  • Declaration of XML prefix mapped to the correct XML namespace URI is allowed.

  • The notation names in a single NotationType attribute declaration and NmTokens in a single Enumeration attribute declaration are distinct.

You can use the P:System.Xml.XmlReaderSettings.ConformanceLevel property to check and guarantee that the stream being read complies with the rules for a well-formed XML 1.0 document or document fragment. If the data doesn't comply, an T:System.Xml.XmlException exception is thrown. The default is F:System.Xml.ConformanceLevel.Document (document-level conformance).

The three conformance levels are:

Setting

Description

Document

Ensures that the XML data conforms to the rules for a well-formed XML 1.0 document. This level of checking ensures that any processor can consume the stream being read as an well-formed XML 1.0 documenthttp://www.w3.org/TR/2006/REC-xml-20060816/#sec-well-formed.

The reader checks for the following:

  • The top-level item must not have any nodes other than XML Declaration, document type definition (DTD), element, comment, white space, or processing instruction.

  • The XML data must have exactly one top-level element node.

Fragment

Ensures that the XML data conforms to the rules for a well-formed XML 1.0 document fragment.

This setting accepts XML data with multiple root elements, or text nodes at the top-level. This level of checking ensures that any processor can consume the stream being read as an external parsed entityhttp://www.w3.org/TR/2006/REC-xml-20060816/#wf-entities.

Auto

Specifies that the reader should determine the level of conformance checking based on the incoming data.

Document conformance checking is applied if the XML data contains DTD information.

Fragment conformance checking is applied if the XML data contains one of following:

  • Text, CDATA, or entity reference node at the root level.

  • More than one element at the root level.

  • No element at the root level.

An T:System.Xml.XmlException is thrown if there is a conflict, such as when there is a text node and a DTD at the root level.

This setting can be used in wrapping scenarios when the Overload:System.Xml.XmlReader.Create method is used to add additional features to an existing T:System.Xml.XmlReader. In this case, F:System.Xml.ConformanceLevel.Document does not add any new conformance checking. Conformance checking is left to the T:System.Xml.XmlReader that is being wrapped.

System_CAPS_noteHinweis

The XML 1.0 recommendation requires document-level conformance when a DTD is present. Therefore, if the reader is configured to support F:System.Xml.ConformanceLevel.Fragment, but the XML data contains a document type definition (DTD), an T:System.Xml.XmlException is thrown.

Here's how the reader handles specific conformance violations depending on the setting of the P:System.Xml.XmlReaderSettings.ConformanceLevel property:

Condition

Document

Fragment

Auto

Text or a typed value appears at the top level.

XmlException is thrown.

Not considered a violation for this setting.

Not considered a violation for this setting.

Multiple elements or no element appear at the top level.

XmlException is thrown.

Not considered a violation for this setting.

Not considered a violation for this setting.

Top-level item is white space.

Not considered a violation for this setting.

Not considered a violation for this setting.

Not considered a violation for this setting.

Top-level item is an attribute (recognized as a text node).

XmlException is thrown.

Not considered a violation for this setting.

Not considered a violation for this setting.

Multiple, contiguous text nodes are found.

Not considered a violation for this setting.

Not considered a violation for this setting.

Not considered a violation for this setting.

The same namespace prefix is declared twice in the same local scope.

XmlException is thrown.

XmlException is thrown.

XmlException is thrown.

The namespace in an element or attribute doesn't exist in the local scope.

XmlException is thrown.

XmlException is thrown.

XmlException is thrown.

Data contains a prefix-namespace mismatch.

XmlException is thrown.

XmlException is thrown.

XmlException is thrown.

xml:space attribute contains an invalid value.

XmlException is thrown.

XmlException is thrown.

XmlException is thrown.

An invalid name is encountered.

XmlException is thrown.

XmlException is thrown.

XmlException is thrown.

The xml prefix isn't matched to the http://www.w3.org/XML/1998/namespace URI.

XmlException is thrown.

XmlException is thrown.

XmlException is thrown.

The following example creates an T:System.Xml.XmlReader object that reads an XML fragment.

string xmlFrag ="<item rk:ID='abc-23'>hammer</item> " +
                        "<item rk:ID='r2-435'>paint</item>" +
                        "<item rk:ID='abc-39'>saw</item>";

// Create the XmlNamespaceManager.
NameTable nt = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
nsmgr.AddNamespace("rk", "urn:store-items");

// Create the XmlParserContext.
XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);

// Create the reader. 
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Fragment;
XmlReader reader = XmlReader.Create(new StringReader(xmlFrag), settings, context);

Universelle Windows-Plattform
Verfügbar seit 8
.NET Framework
Verfügbar seit 2.0
Portierbare Klassenbibliothek
Unterstützt in: portierbare .NET-Plattformen
Silverlight
Verfügbar seit 2.0
Windows Phone Silverlight
Verfügbar seit 7.0
Windows Phone
Verfügbar seit 8.1
Zurück zum Anfang
Anzeigen: