比如我有一张数据库表table1,如后这张表里面有如下数据:
字段1字段2字段3
A 1001 abc
A 1002 abd
A 1003 deg
B 2001 der
B 2002 der
C 3001 der
D 4005 der
D 4002 swe
从数据库里面获取所有数据,以字段1来区分,生成 四个xml文件
也就是说:
A 1001 abc
A 1002 abd
A 1003 deg
这个放在以a.xml文件里面
B 2001 der
B 2002 der
这个放在b.xml文件里面以此类推,请给位大侠赐教,谢谢!
字段1字段2字段3
A 1001 abc
A 1002 abd
A 1003 deg
B 2001 der
B 2002 der
C 3001 der
D 4005 der
D 4002 swe
从数据库里面获取所有数据,以字段1来区分,生成 四个xml文件
也就是说:
A 1001 abc
A 1002 abd
A 1003 deg
这个放在以a.xml文件里面
B 2001 der
B 2002 der
这个放在b.xml文件里面以此类推,请给位大侠赐教,谢谢!
解决方案 »
- 如何计算当前日期是本月的第几周?
- 类属性两种形式
- 求助,一个题目进来看看
- cpu Time = processes[i].TotalProcessorTime拒绝访问
- 关于SqlDataAdapter的简单问题
- 关于FileInfo 类的对象赋值问题
- 寻求delphi7项目转vs2003或vs2005的方案
- 请问这个SQL语句怎么写?
- 请问大家怎样在B/S结构中用C#实现菜单功能,各位有经验的朋友能帮助解决吗?
- 必須使用ReportDocument控件嗎
- TextBox 数据绑定:导致两个集合中的绑定绑定到同一个属性,参数名:bingding
- 为什么我收不到255.255.255.255广播的消息呢。。。那位大虾可以告诉我啊。。。急需啊。。急需。。谢谢啦!!
userdoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><UserStockGroup></UserStockGroup>");
XmlElement newGroup = userdoc.CreateElement("UserStockGroupItem");
newGroup.SetAttribute("name", "自选股");
newGroup.SetAttribute("id", "0");
userdoc.DocumentElement.AppendChild(newGroup);
userdoc.Save("c:\\1.xml");
如:
XmlNode root = xmlDoc.SelectSingleNode("/RoleDefautPage/Roles");
XmlElement xe = xmlDoc.CreateElement("Role");//创建一个<Role>节点
xe.SetAttribute("ID", id);//设置节点 属性
xe.SetAttribute("Name", role);//设置节点 属性
xe.SetAttribute("Status", "0");//设置节点 属性
root.AppendChild(xe);
xmlDoc.Save(file);
{
string srcData = @"A 1001 abc
A 1002 abd
A 1003 deg
B 2001 der
B 2002 der
C 3001 der
D 4005 der
D 4002 swe"; Dictionary<string, XmlDocument> xmlDocs = new Dictionary<string, XmlDocument>(); StringReader reader = new StringReader(srcData);
string line = reader.ReadLine();
while (line != null)
{
string[] parts = line.Split();
XmlDocument xmlDoc = null;
if (xmlDocs.ContainsKey(parts[0]))
xmlDoc = xmlDocs[parts[0]];
else
{
xmlDoc = new XmlDocument();
xmlDoc.LoadXml("<Root></Root>");
xmlDocs.Add(parts[0], xmlDoc);
}
XmlElement ele = xmlDoc.CreateElement("Item");
ele.SetAttribute("Column1", parts[0]);
ele.SetAttribute("Column2", parts[1]);
ele.SetAttribute("Column3", parts[2]);
xmlDoc.DocumentElement.AppendChild(ele);
line = reader.ReadLine();
} foreach (KeyValuePair<string, XmlDocument> pair in xmlDocs)
{
pair.Value.Save("D:\\" + pair.Key + ".xml");
}
}文件内容A.xml:<Root>
<Item Column1="A" Column2="1001" Column3="abc" />
<Item Column1="A" Column2="1002" Column3="abd" />
<Item Column1="A" Column2="1003" Column3="deg" />
</Root>B.xml<Root>
<Item Column1="B" Column2="2001" Column3="der" />
<Item Column1="B" Column2="2002" Column3="der" />
</Root>...
new XElement("root",
new XAttribute("imageWidth","440"),
new XAttribute("imageHeight","250")));
foreach (var v in Enumerable.Range(1, 10))
{
Document.Element("root").Add(new XElement("menu",
new XAttribute("url", String.Format("http://localhost:9671/Web/WorksDetail.aspx?id={0}",v)),
new XAttribute("frame", "_blank"),
new XAttribute("imageUrl", String.Format("images/{0}.jpg",v)))); }
Document.Save("c:\\txt.xml");
{
XmlDocument xmldoc;
XmlNode xmlnode;
XmlElement xmlelem;
XmlElement xmlelem2;
XmlText xmltext; public SaveXml()
{ xmldoc = new XmlDocument();
//加入XML的声明段落
xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
xmldoc.AppendChild(xmlnode);
//加入一个根元素
xmlelem = xmldoc.CreateElement("", "ROOT", "");
xmltext = xmldoc.CreateTextNode("Root Text");
xmlelem.AppendChild(xmltext);
xmldoc.AppendChild(xmlelem);
//加入另外一个元素
xmlelem2 = xmldoc.CreateElement("SampleElement");
xmlelem2 = xmldoc.CreateElement("", "SampleElement", "");
xmltext = xmldoc.CreateTextNode("The text of the sample element");
xmlelem2.AppendChild(xmltext);
xmldoc.ChildNodes.Item(1).AppendChild(xmlelem2);
//保存创建好的XML文档
try
{
xmldoc.Save("d:\\data1.xml");
}
catch (Exception e)
{
//显示错误信息
Console.WriteLine(e.Message);
}
//Console.ReadLine ( ) ;
} }}
<root1 name="df">
<Item Column1="A" Column2="1001" Column3="abc" />
<Item Column1="A" Column2="1002" Column3="abd" />
<Item Column1="A" Column2="1003" Column3="deg" />
<root1>
</Root>我想在里面再多加几个元素 比如让面的root1该怎么加进去啊
while (line != null)
{
string[] parts = line.Split();
XmlDocument xmlDoc = null;
if (xmlDocs.ContainsKey(parts[0]))
xmlDoc = xmlDocs[parts[0]];
else
{
xmlDoc = new XmlDocument();
xmlDoc.LoadXml("<Root></Root>");
XmlElement eleRoot1 = xmlDoc.CreateElement("root1");
eleRoot1.SetAttribute("name", "df");
xmlDoc.DocumentElement.AppendChild(eleRoot1);
xmlDocs.Add(parts[0], xmlDoc);
}
XmlElement ele = xmlDoc.CreateElement("Item");
ele.SetAttribute("Column1", parts[0]);
ele.SetAttribute("Column2", parts[1]);
ele.SetAttribute("Column3", parts[2]);
xmlDoc.DocumentElement["root1"].AppendChild(ele);
line = reader.ReadLine();
}
<Item Column Name="1001" />
这都不符合XML的格式