The attribute value is a simple text string in most cases where the property value is analyzed. However, this does not mean that attribute values in practical applications are characters. Sometimes, attribute values are combined by many types of data, such as Date or Boolean, at this time, you have to convert these types into the original type with XMLConvert or System.convevt classes. Both XMLConvert and System.convevt classes enable conversion of data types, but the XMLConvert class converts the data type specified in XSD, regardless of what type it is now. Suppose you have the following XML data pieces: Let us first confirm that the BIRTHDAAY attribute value is February 8, 2001, if you use the System.convert class to convert the string into. The DateTime type in NET Framework, so we can use it as a Date type. Compared to the XMLConvert class to convert a string, you will see an analysis error because the XMLConvert class does not explain the date in this string. Because in XML, the format of date data must be in YYYY-MM-DD form. The XMLConvert class serves as the mutual conversion between the CLR type and the XSD type. When the conversion work occurs, the conversion result is partial. In some solutions, the attribute value is constructed from plain text and entity. In all reader classes, only XMLValidatingReader class can handle entities. Although XMLTextReader cannot handle entities, they simultaneously appear in the attribute value, it can only take the text value. This happens, you must use the ReadttributeValue method to replace simple readings to analyze the contents of the property. The READATTRIBUTEVALUE method analyzes the property value and then separates the elements of each component (such as separating plain text and entity). You can use the return value of the ReadAttributeValue method as a loop condition, traversing the elements of the entire property value. Since the XMLTextReader class cannot handle the entity, you can write a class that is used to handle the entity. The following code snippet demonstrates how to call a custom processing class: while (reader.ReadattributeValue ()) {if (reader.NodeType == xmlnodetype.entityreference) // resolve the "reader.name" Reference and add // THE Result to a buffer buf = YourResolverCode (Reader.Name); Else // Just Append the value to the buffer buf = reader.value;} After all of the property values are analyzed, the ReadaTributeValue method returns false to end the loop. The final result of the attribute value is the value of the global variable buffer. Handling XML text (text) When we do not process the XML tag text, its error reason can be determined quickly. For example, a character conversion error is inevitably transmitted in an XML data stream. Not all valid characters in a given platform are valid XML characters.
Only valid characters specified in the XML specification (www.w3.rg/tr/2000/rec-xml-20001006.html) can be safely used as elements and attribute names. The XMLConvert class provides features that convert non-XML standards to standard XML naming. Encodename and DecodeEname methods are adjusted into XML naming that complies with Schema when the label name contains invalid XML characters. Includes SQL Server? And Microsoft Office, which allows and supports the Unicode document, however, characters in these documents are not a valid XML naming. Typical situations are when you handle column names that contain spaces in your database. Although SQL Server allows the long name, this may not be a valid naming for XML flow. The space is replaced by hexadecimal code invoice_0x0020_details. The following code demonstrates how to get the string in the program: XmlConvert.Encodename ("Invoice Details); the opposite method is Decodename. This method converts XML text into its original format. It should be noted that it can only convert a complete hexadecimal code, only _0x0020_ is used as a space, and _0x20_ is not: XmlConvert.Decodename ("invoice_0x0020_details); in the XML document Important is not important. Say it is important, it is the actual meaning when it appears in the content of the element or it is in the comment statement. For example, the following case: ??? mynode> In XML, space is not just representing space (blank), also representative Enter, wrap and indent. You can handle spaces through the WhitespaceHandling property of the XMLTextReader class. This attribute accepts and returns a WhitespaceHandling enumeration value (this enumeration class has three optional values). The default is all, which indicates that the meaningful and meaningless space will return as a node ---- SignificantWhitespace and Whitespace nodes, respectively. Another enumeration value is none, which means that it is not returned to any space. Finally, the SignFICANT enumeration value, which means that ignores the meaningless space, and only returns the node of the node type as SignficantWhitespace. Note whitespaceHandling property is one of a few reader properties. It can be changed at any time and giving the read operation. The Normalization and XMLResolver properties are "Sensitive". String and Fragment programmakers cut down the MSXML program and found a lot between COM and .NET Framework XML APIs. The .NET Framework class itself does not provide a method to analyze XML data stored in a string. Unlike MSXML analyzer objects, the XMLTestReader class does not provide any LoadXML method to create a reader from a wellform in a format. No way to provide logadxml because you can get the same feature with a special Text Reader --- StringReader class. XMLTextReader is one of the constructor accepts a TextReader derived object and an XML reader parameter (creating the reader based on the contents of Text Reader). A TEXT Reader class is a stream that is an input character to be generated.