XML保存在数据库中 [英] Xml saved in database

查看:68
本文介绍了XML保存在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想将Xml中的数据作为字符串保存到数据库中,但不熟悉Xml.

基本上,想要一个简单的C#示例,其中创建一个Xml文档(数据无关紧要),并且将字符保存在字符串中以保存在数据库中.

有任何想法吗?

Hi there

I want to save data in Xml to a database as a string but am not familiar with Xml.

Basically, would like a simple C# example where an Xml document is created (the data doesn''t matter), and the characters are saved in a string to be saved in a database.

Any ideas?

推荐答案

这是一个非常简单的示例.
Here is a very simple example.
/* Create XML document. */
System.Xml.XmlDocument d = new System.Xml.XmlDocument();
d.LoadXml(@"<animals><dog name=""Ruff"" /><cat name=""Nip"" /></animals>");

/* Get XML as string. */
string str = d.OuterXml;


与其他任何字符串一样,将该字符串保存到数据库中.确保使用可以容纳长字符串的数据类型(如果XML可能很大).


Save that string to the database as you would any other string. Make sure to use a data type that can hold a long string (if your XML has the potential to be large).


这篇关于XML保存在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆