数据库批量更新,添加!有关XML的操作
得到一个需要处理的XMl
private string GetSaveItem()
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml("<menuCollection/>");
foreach (TreeNode node in trvAccessRight.CheckedNodes)
{
if (node != trvAccessRight.Nodes[0])
{
XmlElement content = xmlDoc.CreateElement("menuItem");
content.SetAttribute("menuID", node.Value);
xmlDoc.DocumentElement.AppendChild(content);
}
}
return xmlDoc.OuterXml;
}
将以上的获得的XMl字符串当参数传入存储过程中,
存储如下写
ALTER PROCEDURE [dbo].[usp_UserGroup_SetRight]
(@GroupID INT ,@ChangedBy VARCHAR(50) ,@MenuXml XML)
AS
BEGIN
--SET XACT_ABORT ON
BEGIN TRY
BEGIN TRANSACTION
--delete
DELETE
from tbl_SysUserGroupRight
WHERE GroupId = @GroupID
--insert
INSERT INTO tbl_SysUserGroupRight
(
GroupId
,MenuID
,ChangedBy
,ChangedOn
)
SELECT @GroupID
,menuList.row.value(N'@menuID' ,'VARCHAR(50)') AS MenuID
,@ChangedBy
,GETDATE()
from @MenuXml.nodes('/menuCollection/menuItem') AS menuList(row)
COMMIT TRANSACTION
RETURN 1
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
RETURN 0
END CATCH
更新可以借鉴上面的添加操作,
相关文档:
xml中有以下字符不能出现,否则,xml将不能被正确解析:
&><'
如果在xml中出现了非法字符呢必须将其过滤掉!过滤的方法很简单,替换就可以了:
例如在php xml_parser_create 中,就可以这么做:
$parser = xml_parser_create(); //创建一个parser编辑器
xml_set_element_handler($parser, "startElement", " ......
VC解析XML--使用CMarkup类解析XML
(一) 先讲一下XML中的物殊字符,手动填写时注意一下。
字符 字符实体
& &nb ......
源xml文件
<?xml version="1.0" encoding="iso-8859-1"?>
<books>
<stock>
<name>The Picasso Code</name>
<author>Dan Blue</author>
<category>Fiction</category>
<description>Cubist paintings reveal a secret society of people ......
flex和spring+hibernate整合完成后web.XML出现如下错误
The content of element type "web-app" must match "(icon?,display-name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime-mapping*,welcome-file-list?,error-page*,taglib*,reso ......
<?xml version="1.0" encoding="UTF-8"?>
<projects>
<node Country="暗暗啊" Gold="10" Silver="20" Bronze="30"/>
<node Country="白斑病" Gold="30" Silver="20" Bronze="10"/>
<node Country="常常厂" Gold="20" Silver="40" Bronze="60"/>
<node Country="赌东道" Gold="5 ......