求一个XML操作类,可付费...

qq1480801 2010-12-12 12:37:13

<?xml version="1.0" encoding="GB2312"?>
<!-- edited with XMLSPY v2004 rel. 2 U (http://www.xmlspy.com) by liulp (one) -->
<manifest identifier="yhd" version="1.0" xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2" xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd">
<organizations default="TOC0">
<organization identifier="TOC0">
<title>中级财务会计</title>
<item isvisible="false" identifier="t01" reworkable="true" isrecord="false" identifierref="" >
<title>通用模块</title>
<item isvisible="false" identifier="t01t01" reworkable="true" isrecord="false" identifierref="resourcet01t01">
<title>课程首页</title>
</item>
<item isvisible="false" identifier="t01t02" reworkable="true" isrecord="false" identifierref="resourcet01t02">
<title>课程信息</title>
</item>
<item isvisible="false" identifier="t01t03" reworkable="true" isrecord="false" identifierref="resourcet01t03">
<title>教学队伍</title>
</item>
</item>
<item isvisible="true" identifier="c01" reworkable="true" isrecord="false" identifierref="">
<title>第1单元 总论ss</title>
<item isvisible="true" identifier="c01k01" reworkable="true" isrecord="true" identifierref="">
<title>导学</title>
<item isvisible="true" identifier="c01k01sco01" reworkable="true" isrecord="true" identifierref="resourcec01k01sco01">
<title>学习指南</title>
</item>
<item isvisible="true" identifier="c01k01sco02" reworkable="true" isrecord="true" identifierref="resourcec01k01sco02">
<title>问题引导</title>
</item>
</item>
<item isvisible="true" identifier="c01k02" reworkable="true" isrecord="true" identifierref="" >
<title>自学</title>
<item isvisible="true" identifier="c01k02sco01" reworkable="false" isrecord="true" identifierref="resourcec01k02sco01" >
<title>知识要点</title>
</item>
<item isvisible="true" identifier="c01k02sco02" reworkable="false" isrecord="true" identifierref="resourcec01k02sco02">
<title>单元测试</title>
</item>
</item>
</item>
<metadata>
<schema>ADL SCORM</schema>
<schemaversion>1.2</schemaversion>
<adlcp:location>metadata.xml</adlcp:location>
</metadata>
</organization>
</organizations>
<resources>
<resource identifier="resourcet01t01" type="webcontent" adlcp:scormtype="sco" href="content/t01/t01t01.htm">
<file href="content/t01/t01t01.htm" />
</resource>
<resource identifier="resourcet01t02" type="webcontent" adlcp:scormtype="sco" href="content/t01/t01t02.htm">
<file href="content/t01/t01t02.htm" />
</resource>
<resource identifier="resourcet01t03" type="webcontent" adlcp:scormtype="sco" href="content/t01/t01t03.htm">
<file href="content/t01/t01t03.htm" />
</resource>
<resource identifier="resourcec01k01sco01" type="webcontent" adlcp:scormtype="sco" href="content/c01/c01k01sco01.htm">
<file href="content/c01/c01k01sco01.htm" />
<menuPic href="content/images/menuBtn1.jpg" />
<page pageCount="4" />
</resource>
<resource identifier="resourcec01k01sco02" type="webcontent" adlcp:scormtype="sco" href="content/c01/c01k01sco02.htm">
<file href="content/c01/c01k01sco02.htm" />
</resource>
<resource identifier="resourcec01k02sco01" type="webcontent" adlcp:scormtype="sco" href="content/c01/c01k02sco01.htm">
<file href="content/c01/c01k02sco01.htm" />
</resource>
<resource identifier="resourcec01k02sco02" type="webcontent" adlcp:scormtype="sco" href="content/c01/c01k02sco02.htm">
<file href="content/c01/c01k02sco02.htm" />
</resource>
</resources>
</manifest>



要求操作这样一个XML
resources中的数据是对应着上面item数据的,注意看ID有对应值

各位高手出来帮帮忙吧,谢谢....

可以付费的
...全文
194 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq1480801 2010-12-13
  • 打赏
  • 举报
回复

没人管了吗??


高手快来帮帮忙啊 谢谢谢谢.......
lcomplete 2010-12-12
  • 打赏
  • 举报
回复
七爷 2010-12-12
  • 打赏
  • 举报
回复
不知道你要如何操作,
七爷 2010-12-12
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 qq1480801 的回复:]
汗...我对操作XML根据算是一张白纸,现在我意思是要写出操作示例XML中这种数据,

我可以付费的...
[/Quote]
建议你还是百度搜下把,然后自己研究研究,还能提升自己,钱未必能买到所有的东西的。
qq1480801 2010-12-12
  • 打赏
  • 举报
回复
汗...我对操作XML根据算是一张白纸,现在我意思是要写出操作示例XML中这种数据,

我可以付费的...
whb147 2010-12-12
  • 打赏
  • 举报
回复
baidu搜索XML操作类库,就有一大堆
wuyq11 2010-12-12
  • 打赏
  • 举报
回复
XmlNamespaceManager
XmlDocument d = new XmlDocument();
d.Load(Server.MapPath("~/A.xml"));
XmlNamespaceManager m = new XmlNamespaceManager(d.NameTable);
m.AddNamespace("A", "http://www.imsproject.org/xsd/imscp_rootv1p1p2");
m.AddNamespace("msdata", "urn:schemas-microsoft-com:xml-msdata");
XmlNodeList ns = d.SelectNodes("",m);
foreach (XmlNode n in ns)
{
Response.Write("<li>"+n.Attributes["name"].Value);
}
qq1480801 2010-12-12
  • 打赏
  • 举报
回复
还是非常感谢你们...有能帮助我的兄弟麻烦伸出援助之手- -~~~~
qq1480801 2010-12-12
  • 打赏
  • 举报
回复
别处copy过来的就没必要了吧...


能帮的上的帮莪针对这个XML来写吧...
我说了 我也可以付费的..我自己要有时间学我就学了,公司的事情太急了.....
  • 打赏
  • 举报
回复
收不到钱,还不够着急的。
  • 打赏
  • 举报
回复
付费多少?call me~哟呼~~~
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wuyq11 的回复:]
XmlNamespaceManager
XmlDocument d = new XmlDocument();
d.Load(Server.MapPath("~/A.xml"));
XmlNamespaceManager m = new XmlNamespaceManager(d.NameTable);
m.AddNamespace("A", "http://www.imsproject.……
[/Quote]

学习了
wangxingny 2010-12-12
  • 打赏
  • 举报
回复
说到底,就是解析xml么?楼上的意见都可以。
chengfellow 2010-12-12
  • 打赏
  • 举报
回复
一 写XML

方法一:

internal static void writeAnXml() {
XmlTextWriter writer = new XmlTextWriter(@"c:\employee.xml", Encoding.UTF8);
writer.Formatting = Formatting.Indented; //缩进格式
writer.Indentation = 4;

writer.WriteStartDocument();

writer.WriteStartElement("Person"); //根元素

writer.WriteStartElement("ID");//子元素
writer.WriteString("004");
writer.WriteEndElement();

writer.WriteStartElement("Name");//子元素
writer.WriteString("testWriterName");
writer.WriteEndElement();

writer.WriteStartElement("Number");//子元素
writer.WriteString("88888");
writer.WriteStartElement("City");//子元素
writer.WriteStartAttribute("Province",null);//属性
writer.WriteString("河南");
writer.WriteEndAttribute();
writer.WriteStartAttribute("Code", null);
writer.WriteString("0371");
writer.WriteEndAttribute();
writer.WriteString("郑州");
writer.WriteEndElement();

writer.WriteStartElement("Hobby");
writer.WriteStartElement("PE");
writer.WriteString("篮球");
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();//关闭根元素

writer.WriteEndDocument();//关闭xml文档
writer.Flush();
writer.Close();
}

方法二:

internal static void writeX() {
XmlDocument xmldoc;
XmlNode xmlnode;
XmlElement xmlelem;
XmlElement xmlelem2;
XmlText xmltext;
XmlAttribute xmlAttr;
xmldoc = new XmlDocument();
//加入XML的声明段落
xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration,"","");
xmldoc.AppendChild(xmlnode);
//加入一个根元素
//xmlelem = xmldoc.createElement_x_x_x_x("", "ROOT", "");
//xmlAttr = xmldoc.CreateAttribute("ID");//创建元素属性
//xmlAttr.Value = "001";
//xmlelem.Attributes.Append(xmlAttr);//附加到元素
////xmlelem.AppendChild(xmltext);
//xmldoc.AppendChild(xmlelem);

xmlelem = xmldoc.createElement_x_x_x_x("Root");
xmldoc.AppendChild(xmlelem);

xmlelem2 = xmldoc.createElement_x_x_x_x("Leaf");
xmltext = xmldoc.CreateTextNode("001");
xmlelem2.AppendChild(xmltext);

xmldoc.ChildNodes.Item(1).AppendChild(xmlelem2);
//保存创建好的XML文档
try
{
xmldoc.Save("c:\\data.xml");
}
catch (Exception e)
{
//显示错误信息
Console.WriteLine(e.Message);
}
}

方法三:

internal static void readXml() {
// 创建一个XmlDocument类的对象
XmlDocument doc = new XmlDocument();

string appPath = System.AppDomain.CurrentDomain.BaseDirectory;
doc.LoadXml(("<Student type='regular' Section='B'>

<Name>TommyLex</Name></Student>"));
//Console.WriteLine(appPath);
// 保存到文件中
doc.Save(appPath+"..\\..\\student.xml");
}

二 读XML

方法一:使用XmlTextReader

internal static void readX() {
// 创建一个XmlTextReader类的对象并调用Read方法来读取文件
XmlTextReader textReader = new XmlTextReader("C:\\data.xml");
//textReader.Read();
// 节点非空则执行循环体
int count = 0;
while (textReader.Read())
{
// 读取第一个元素
textReader.MoveToElement();
//Console.WriteLine("XmlTextReader Properties Test");
// 读取该元素的属性并显示在控制台中
//if (textReader.Name !=string.Empty) {
Console.WriteLine("===================");
Console.WriteLine("Name:" + textReader.Name);
//Console.WriteLine("Base URI:" + textReader.BaseURI);
Console.WriteLine("Local Name:" + textReader.LocalName);
//Console.WriteLine("Attribute Count:" + textReader.AttributeCount.ToString());
//Console.WriteLine("Depth:" + textReader.Depth.ToString());
Console.WriteLine("Line Number:" + textReader.LineNumber.ToString());
Console.WriteLine("Node Type:" + textReader.NodeType.ToString());
Console.WriteLine("Current Text Value:" + textReader.Value.ToString());
count++;
//}
}

if (textReader != null)
textReader.Close();
Console.WriteLine("count:{0}", count);
}

方法二:使用XmlNodeReader

public static void nodeReader() {
XmlNodeReader reader=null;
try
{
string s = "";
XmlDocument doc = new XmlDocument();
// 装入指定的XML文档
doc.Load("C:\\employee.xml");
// 设定XmlNodeReader对象来打开XML文件
reader = new XmlNodeReader(doc);
// 读取XML文件中的数据,并显示出来
while (reader.Read())
{
//判断当前读取得节点类型
switch (reader.NodeType)
{
case XmlNodeType.Element:
s = reader.Name;
break;
case XmlNodeType.Text:
if (s.Equals("Name"))
Console.WriteLine(reader.Value);//输出当前节点的值
if (s.Equals("Number"))
Console.WriteLine(reader.Value);//输出当前节点的值
break;
}
}
}
finally
{
//清除打开的数据流
if (reader != null)
reader.Close();
}
}

public static void NodeReaderAll()
{
XmlNodeReader reader = null;
try
{
XmlDocument doc = new XmlDocument();
// 装入指定的XML文档
doc.Load("C:\\employee.xml");
// 设定XmlNodeReader对象来打开XML文件
reader = new XmlNodeReader(doc);
// 读取XML文件中的数据,并显示出来
while (reader.Read())
{
//判断当前读取得节点类型
switch (reader.NodeType)
{
case XmlNodeType.Element:
if (reader.HasAttributes)
{
for (int i = 0; i < reader.AttributeCount; i++)
{
reader.MoveToAttribute(i);
Console.WriteLine("AttrName:{0},AttrValue:{1}", reader.Name, reader.Value);//输出当前节点属性值
}
}
break;
case XmlNodeType.Text:
Console.WriteLine("TextValue:{0}", reader.Value);//输出当前节点的值
break;
}
}
}
finally
{
//清除打开的数据流
if (reader != null)
reader.Close();
}
}
wwfgu00ing 2010-12-12
  • 打赏
  • 举报
回复
 public static string GetXmlValue(string xmlContent, string xmlKey)
{
string xmlValue = "";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlContent);
XmlNode xnode = xmlDoc.DocumentElement;
foreach (XmlNode node in xnode.ChildNodes)
{
if (node.Attributes[0].Value == xmlKey)
{
xmlValue = node.InnerText;
}
}
return xmlValue;
}
winner2050 2010-12-12
  • 打赏
  • 举报
回复
读取为DataSet 以后就跟操作数据库一样了。
shangwg 2010-12-12
  • 打赏
  • 举报
回复
听不懂,顶
qq1480801 2010-12-12
  • 打赏
  • 举报
回复


就是添删改查

添加要可以添加任意两大节点中的item item中还会有title和item,依次还会出现
其中两大节点指的是
<organizations default="TOC0">
<organization identifier="TOC0">内的是要可控制的

然后resources中的也要可以操作的..
修改就一样的规则了
删就不用说了,任意动态节点都要可删除

然后以树形目录结构查询这些数据.

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧