首页
老网站
正文
XML技巧五则
发布日期:
2008.01.06
浏览:
2405次 关键字:
XML 技巧
{$ad$}
技巧1
XmlNode.InnerText与.InnerXml的区别是:前者将内容中的<和>分别变成<和>,因此,希望将两段 XmlDocument 合并的程序只能使用
XmlDocumentFragment.InnerXml = XmlNode.OuterXml
技巧2
/XPath: string end-with
<xsl:for-each select="root/data[substring-after(@name,'.')=
'Text' and string-length(value)>0]">
技巧3
一个XML文档在Load时如果失败,就是根本不合法;是否符合某个Schema(XSD)的要求则是有效性(valid)检查,方法是使用XmlValidatingReader对象的Schemas和ValidationType属性。
技巧4
XmlDataDocument类是从XmlDocument派生出来的,最重要的是增加了一个DataSet属性。不过这个类不是System.Xml提供的,而是System.Data提供的。对于总是要跟数据库打交道的应用程序来说,反正是要引用System.Data的,不如全部用XmlDataDocument。
技巧5
如何将XmlDataDocument对象中的DataSet更新保存到数据库中?DataSet本身有一个AcceptChanges方法,所以只需要:
xmlDataDoc.DataSet.AcceptChanges();
SELECT [t0].[class_id]
FROM [dbo].[mvc_class_channel] AS [t0]
WHERE ([t0].[class_id] = @p0) OR ([t0].[class_id_path] LIKE @p1) OR ([t0].[class_id_path] LIKE @p2)
-- @p0: Input BigInt (Size = 0; Prec = 0; Scale = 0) [368]
-- @p1: Input NVarChar (Size = 7; Prec = 0; Scale = 0) [%|368|%]
-- @p2: Input NVarChar (Size = 5; Prec = 0; Scale = 0) [368|%]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 3.5.30729.1
SELECT COUNT(*) AS [value]
FROM [dbo].[mvc_content_view] AS [t0]
WHERE ([t0].[a_type] IN (@p0)) AND (NOT ([t0].[a_isRecycle] = 1)) AND ([t0].[a_model] = @p1)
-- @p0: Input BigInt (Size = 0; Prec = 0; Scale = 0) [368]
-- @p1: Input BigInt (Size = 0; Prec = 0; Scale = 0) [24]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 3.5.30729.1
SELECT TOP (30) [t0].[a_id], [t0].[a_type], [t0].[a_name], [t0].[a_create_date], [t0].[a_hits], [t0].[a_isimg], [t0].[a_imgurl], [t0].[a_ismedia], [t0].[a_mediaurl], [t0].[a_model_name]
FROM [dbo].[mvc_content_view] AS [t0]
WHERE ([t0].[a_type] IN (@p0)) AND (NOT ([t0].[a_isRecycle] = 1)) AND ([t0].[a_model] = @p1)
ORDER BY [t0].[a_id] DESC
-- @p0: Input BigInt (Size = 0; Prec = 0; Scale = 0) [368]
-- @p1: Input BigInt (Size = 0; Prec = 0; Scale = 0) [24]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 3.5.30729.1
SELECT TOP (4) [t0].[a_id], [t0].[a_site], [t0].[a_model], [t0].[a_type], [t0].[a_special], [t0].[a_name], [t0].[a_from], [t0].[a_from_url], [t0].[a_author], [t0].[a_editor], [t0].[a_describe], [t0].[a_content], [t0].[a_create_date], [t0].[a_tag], [t0].[a_hits], [t0].[a_commend], [t0].[a_istop], [t0].[a_isimg], [t0].[a_cacheimg], [t0].[a_imgurls], [t0].[a_imgurl], [t0].[a_ismedia], [t0].[a_mediaurl], [t0].[a_iscomment], [t0].[a_isRecycle], [t0].[a_weight], [t0].[a_weights], [t0].[a_status], [t0].[a_url], [t0].[a_file_path], [t0].[a_contentfile], [t0].[a_comment], [t0].[a_ispass], [t0].[a_bury], [t0].[a_dig], [t0].[a_score], [t0].[a_rank], [t0].[a_diguser], [t0].[a_buryuser], [t0].[a_viewip], [t0].[a_lastviewdate], [t0].[a_neworimageorvideo], [t0].[class_id], [t0].[class_type], [t0].[class_name], [t0].[class_show_name], [t0].[class_parent_id], [t0].[class_id_path], [t0].[class_name_path], [t0].[class_show_name_path], [t0].[class_depth], [t0].[class_order], [t0].[class_content], [t0].[class_img], [t0].[a_model_name]
FROM [dbo].[mvc_content_view] AS [t0]
WHERE ([t0].[a_isimg] = 1) AND ([t0].[a_type] IN (@p0)) AND (NOT ([t0].[a_isRecycle] = 1))
ORDER BY [t0].[a_id] DESC
-- @p0: Input BigInt (Size = 0; Prec = 0; Scale = 0) [368]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 3.5.30729.1
SELECT TOP (1) [t0].[a_id], [t0].[a_site], [t0].[a_model], [t0].[a_type], [t0].[a_special], [t0].[a_name], [t0].[a_from], [t0].[a_from_url], [t0].[a_author], [t0].[a_editor], [t0].[a_describe], [t0].[a_content], [t0].[a_create_date], [t0].[a_tag], [t0].[a_hits], [t0].[a_commend], [t0].[a_istop], [t0].[a_isimg], [t0].[a_cacheimg], [t0].[a_imgurls], [t0].[a_imgurl], [t0].[a_ismedia], [t0].[a_mediaurl], [t0].[a_iscomment], [t0].[a_isRecycle], [t0].[a_weight], [t0].[a_weights], [t0].[a_status], [t0].[a_url], [t0].[a_file_path], [t0].[a_contentfile], [t0].[a_comment], [t0].[a_ispass], [t0].[a_bury], [t0].[a_dig], [t0].[a_score], [t0].[a_rank], [t0].[a_diguser], [t0].[a_buryuser], [t0].[a_viewip], [t0].[a_lastviewdate], [t0].[a_neworimageorvideo], [t0].[class_id], [t0].[class_type], [t0].[class_name], [t0].[class_show_name], [t0].[class_parent_id], [t0].[class_id_path], [t0].[class_name_path], [t0].[class_show_name_path], [t0].[class_depth], [t0].[class_order], [t0].[class_content], [t0].[class_img], [t0].[a_model_name]
FROM [dbo].[mvc_content_view] AS [t0]
WHERE ([t0].[a_type] IN (@p0)) AND (NOT ([t0].[a_isRecycle] = 1))
ORDER BY [t0].[a_istop] DESC, [t0].[a_id] DESC
-- @p0: Input BigInt (Size = 0; Prec = 0; Scale = 0) [368]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 3.5.30729.1
SELECT [t1].[a_id], [t1].[a_type], [t1].[a_name], [t1].[a_imgurl], [t1].[a_model_name]
FROM (
SELECT TOP (2) [t0].[a_id], [t0].[a_type], [t0].[a_name], [t0].[a_hits], [t0].[a_imgurl], [t0].[a_model_name]
FROM [dbo].[mvc_content_view] AS [t0]
WHERE ([t0].[a_isimg] = 1) AND ([t0].[a_type] IN (@p0)) AND (NOT ([t0].[a_isRecycle] = 1))
ORDER BY [t0].[a_hits] DESC, [t0].[a_id] DESC
) AS [t1]
ORDER BY [t1].[a_hits] DESC, [t1].[a_id] DESC
-- @p0: Input BigInt (Size = 0; Prec = 0; Scale = 0) [368]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 3.5.30729.1
SELECT [t1].[a_id], [t1].[a_type], [t1].[a_name], [t1].[a_imgurl], [t1].[a_model_name]
FROM (
SELECT TOP (7) [t0].[a_id], [t0].[a_type], [t0].[a_name], [t0].[a_hits], [t0].[a_imgurl], [t0].[a_model_name]
FROM [dbo].[mvc_content_view] AS [t0]
WHERE ([t0].[a_type] IN (@p0)) AND (NOT ([t0].[a_isRecycle] = 1))
ORDER BY [t0].[a_hits] DESC, [t0].[a_id] DESC
) AS [t1]
ORDER BY [t1].[a_hits] DESC, [t1].[a_id] DESC
-- @p0: Input BigInt (Size = 0; Prec = 0; Scale = 0) [368]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 3.5.30729.1
SELECT [t1].[a_id], [t1].[a_type], [t1].[a_name], [t1].[a_content], [t1].[a_imgurl], [t1].[a_model_name]
FROM (
SELECT TOP (10) [t0].[a_id], [t0].[a_type], [t0].[a_name], [t0].[a_content], [t0].[a_hits], [t0].[a_imgurl], [t0].[a_model_name]
FROM [dbo].[mvc_content_view] AS [t0]
WHERE (NOT ([t0].[a_isRecycle] = 1)) AND ([t0].[a_site] = @p0)
ORDER BY [t0].[a_hits] DESC, [t0].[a_id] DESC
) AS [t1]
ORDER BY [t1].[a_hits] DESC, [t1].[a_id] DESC
-- @p0: Input BigInt (Size = 0; Prec = 0; Scale = 0) [298]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 3.5.30729.1
SELECT [t0].[a_id], [t0].[a_site], [t0].[a_model], [t0].[a_type], [t0].[a_special], [t0].[a_name], [t0].[a_from], [t0].[a_from_url], [t0].[a_author], [t0].[a_editor], [t0].[a_describe], [t0].[a_content], [t0].[a_create_date], [t0].[a_tag], [t0].[a_hits], [t0].[a_commend], [t0].[a_istop], [t0].[a_isimg], [t0].[a_cacheimg], [t0].[a_imgurls], [t0].[a_imgurl], [t0].[a_ismedia], [t0].[a_mediaurl], [t0].[a_iscomment], [t0].[a_isRecycle], [t0].[a_weight], [t0].[a_weights], [t0].[a_status], [t0].[a_url], [t0].[a_file_path], [t0].[a_contentfile], [t0].[a_comment], [t0].[a_ispass], [t0].[a_bury], [t0].[a_dig], [t0].[a_score], [t0].[a_rank], [t0].[a_diguser], [t0].[a_buryuser], [t0].[a_viewip], [t0].[a_lastviewdate], [t0].[a_neworimageorvideo], [t0].[class_id], [t0].[class_type], [t0].[class_name], [t0].[class_show_name], [t0].[class_parent_id], [t0].[class_id_path], [t0].[class_name_path], [t0].[class_show_name_path], [t0].[class_depth], [t0].[class_order], [t0].[class_content], [t0].[class_img], [t0].[a_model_name]
FROM [dbo].[mvc_content_view] AS [t0]
WHERE ([t0].[a_id] = @p0) AND ([t0].[a_type] = @p1) AND (NOT ([t0].[a_isRecycle] = 1))
-- @p0: Input BigInt (Size = 0; Prec = 0; Scale = 0) [4455]
-- @p1: Input BigInt (Size = 0; Prec = 0; Scale = 0) [236]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 3.5.30729.1
SELECT TOP (1) [t0].[a_id], [t0].[a_name]
FROM [dbo].[mvc_content_view] AS [t0]
WHERE ([t0].[a_type] = @p0) AND ([t0].[a_id] < @p1) AND (NOT ([t0].[a_isRecycle] = 1))
ORDER BY [t0].[a_id] DESC
-- @p0: Input BigInt (Size = 0; Prec = 0; Scale = 0) [236]
-- @p1: Input BigInt (Size = 0; Prec = 0; Scale = 0) [4455]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 3.5.30729.1
SELECT TOP (1) [t0].[a_id], [t0].[a_name]
FROM [dbo].[mvc_content_view] AS [t0]
WHERE ([t0].[a_type] = @p0) AND ([t0].[a_id] > @p1) AND (NOT ([t0].[a_isRecycle] = 1))
ORDER BY [t0].[a_id]
-- @p0: Input BigInt (Size = 0; Prec = 0; Scale = 0) [236]
-- @p1: Input BigInt (Size = 0; Prec = 0; Scale = 0) [4455]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 3.5.30729.1
SELECT TOP (10) [t0].[a_id], [t0].[a_site], [t0].[a_model], [t0].[a_type], [t0].[a_special], [t0].[a_name], [t0].[a_from], [t0].[a_from_url], [t0].[a_author], [t0].[a_editor], [t0].[a_describe], [t0].[a_content], [t0].[a_create_date], [t0].[a_tag], [t0].[a_hits], [t0].[a_commend], [t0].[a_istop], [t0].[a_isimg], [t0].[a_cacheimg], [t0].[a_imgurls], [t0].[a_imgurl], [t0].[a_ismedia], [t0].[a_mediaurl], [t0].[a_iscomment], [t0].[a_isRecycle], [t0].[a_weight], [t0].[a_weights], [t0].[a_status], [t0].[a_url], [t0].[a_file_path], [t0].[a_contentfile], [t0].[a_comment], [t0].[a_ispass], [t0].[a_bury], [t0].[a_dig], [t0].[a_score], [t0].[a_rank], [t0].[a_diguser], [t0].[a_buryuser], [t0].[a_viewip], [t0].[a_lastviewdate], [t0].[a_neworimageorvideo], [t0].[class_id], [t0].[class_type], [t0].[class_name], [t0].[class_show_name], [t0].[class_parent_id], [t0].[class_id_path], [t0].[class_name_path], [t0].[class_show_name_path], [t0].[class_depth], [t0].[class_order], [t0].[class_content], [t0].[class_img], [t0].[a_model_name]
FROM [dbo].[mvc_content_view] AS [t0]
WHERE ([t0].[a_type] IN (@p0)) AND (NOT ([t0].[a_isRecycle] = 1))
ORDER BY [t0].[a_id] DESC
-- @p0: Input BigInt (Size = 0; Prec = 0; Scale = 0) [236]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 3.5.30729.1