易截截图软件、单文件、免安装、纯绿色、仅160KB

Integration with the XML Data Type

Integration with the XML Data Type
With the introduction of the XML data type, we wanted to also give FOR XML the ability to generate an instance of XML directly (more precisely, it generates a single row, single column rowset where the cell contains the XML data type instance).
Because of the backwards-compatibility considerations outlined above, we added a new TYPE directive to generate the result as XML. For example,
Copy
SELECT * from Customers FOR XML AUTO, TYPE
returns the Customers elements as an XML data type instance, instead of the nvarchar(max) instance that would have been the case without the TYPE directive.
This result is guaranteed to conform to the well-formedness constraints provided by the XML data type. Since the result is an XML data type instance, you can also use XQuery expressions to query and reshape the result. For example, the following expression retrieves the Customer contact name into a new Person element.
Copy
SELECT (SELECT * from Customers FOR XML AUTO, TYPE).query(
'<doc>{
for $c in /Customers
return
<Person name="{data($c/@ContactName)}"/>
}</doc>')
returns (only first elements shown),
Copy
<doc>
<Person name="Maria Anders" />
<Person name="Ana Trujillo" />
<Person name="Antonio Moreno" />
...
</doc>
Assigning FOR XML Results
Since FOR XML queries now return assignable values, the result of a FOR XML query can be assigned to a variable, or inserted into a column.
Copy
DECLARE @cust XML;
SET @cust = (SELECT * from Customers FOR XML AUTO, TYPE)
CREATE TABLE T(i int, x XML)
INSERT INTO T SELECT 1, (SELECT * from Customers FOR XML AUTO, TYPE)
Nesting of FOR XML Expressions
FOR XML, in SQL Server 2005, recognizes XML data type columns, and will inline them as sub-elements. Thus, we can nest FOR XML queries to generate hierarchies, instead of having to rely on the AUTO mode heuristic, or writing an EXPLICIT mode query.
Let's look


相关文档:

DataSet与xml文件的互相转换


http://www.cnblogs.com/long2006sky/articles/1258731.html
DataSet转换为xml文件
//将DataSet转换为xml文件
        private static void ConvertDataSetToXMLFile(DataSet xmlDS, string xmlFile)
        {
    &n ......

XMLTextReader对XML文件的读取

using System;
using System.Xml;
namespace ReadXMLfromFile
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{
XmlTextReader reader = new XmlTextReader ("books.xml");
......

XML 实体引用

在 XML 中,一些字符拥有特殊的意义。
如果你把字符 "<" 放在 XML 元素中,会发生错误,这是因为解析器会把它当作新元素的开始。
这样会产生 XML 错误:
<message>if salary < 1000 then</message>
为了避免这个错误,用一个实体引用来代替 "<" 字符:
<message>if salary < 1000 then ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号