我现在想把下一个xml字符串的所有<Path>节点的内容放入一个string[]数组中,请问我该怎么做呢?有最简单的方法没?
------------------------------------
string data = @
"<Files>
<File>
<Path>2007/08/31/200783118012709799872943.jpg</Path>
<Desc>SoftDown</Desc>
<Order>3</Order>
<Size>12 KB</Size>
</File>
<File>
<Path>2007/08/31/200783118012756354308724.jpg</Path>
<Desc>SoftDown</Desc>
<Order>4</Order>
<Size>12</Size>
</File>
<File>
<Path>2007/08/31/200783017719286308162841.jpg</Path>
<Desc>SoftDown</Desc>
<Order>5</Order>
<Size>12 KB</Size>
</File>
....
</Files>";
------------------------------------
string data = @
"<Files>
<File>
<Path>2007/08/31/200783118012709799872943.jpg</Path>
<Desc>SoftDown</Desc>
<Order>3</Order>
<Size>12 KB</Size>
</File>
<File>
<Path>2007/08/31/200783118012756354308724.jpg</Path>
<Desc>SoftDown</Desc>
<Order>4</Order>
<Size>12</Size>
</File>
<File>
<Path>2007/08/31/200783017719286308162841.jpg</Path>
<Desc>SoftDown</Desc>
<Order>5</Order>
<Size>12 KB</Size>
</File>
....
</Files>";
解决方案 »
- 请问,Web控件
- IE浏览器设置问题,浏览任何DropList的内容都是白板
- 本地做的网站上传图片可以,但是放到服务器上,就不能上传图片,是什么原因,急
- [flyin2006]请问csdn代码的登录部分怎么写的?
- IIS6 不能播放视频
- 大虾们 请进来帮帮我!有关conn文件中的数据库连接问题
- 在ASP.NET+c# 下如何获得当前系统时间啊?有函数吗??
- 那位能让datagrid中的pagersytle中参数mode在表的下面去掉,不留任何东西。
- 100分求不够在加在ASP里面怎么查询数据库里面是否包含某个字段
- 我的ASP.NET的WEBFORM调试总出现很奇怪的问题.
- 一个DataGrid绑定数据的问题
- 如何在WebForm页面上播放MTV?????????????????祝大家中秋快乐```
public string[] GetDbValueFromXml(string sUpHTMLName,string sUpDBName, string strCol, string sSourceWebsite, int productType, string sProductTypeText, int snatchID)
{
string[] arr = null;
string str = "";
string strXPath = "//Product[@type='" + sProductTypeText + "' and @webURL='" + sSourceWebsite + "']/DBField/HtmlField[@name='" + sUpHTMLName + "']/ValueRelations/Relation";
XmlNodeList xList = xmlDoc.SelectNodes(strXPath);//节点列表
if (xList != null)
{
foreach (XmlNode xn in xList)
{
XmlElement xe = (XmlElement)xn;
string sAttName = xe.GetAttribute("htmlValue");
str += sAttName + ",";
}
arr = str.Split(",");
}
return arr;
}
xmlDoc = new XmlDocument();
xmlDoc.Load(xmlConnectionStr);
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("data.xml"));
XmlNodeList xmllist = xmldoc.SelectNodes("//Files/File");
string[] a = new string [xmllist.Count];
foreach (XmlNode xmlnode in xmllist)
{
a[i] = xmlnode.SelectSingleNode("Path").InnerText;
i++;
}
记得加这句
那么我可以用什么简便方法把所有<Path>节点的内容放入一个string[]数组中吗?
string data = @
"<Files>
<File>
<Path>2007/08/31/200783118012709799872943.jpg</Path>
<Desc>SoftDown</Desc>
<Order>3</Order>
<Size>12 KB</Size>
</File>
....
</Files>";
StringReader sr = new StringReader(data);XmlDocument doc = new XmlDocument();
doc.Load(sr);
string[] strs = new string[lst.Count];
XmlNodeList lst = doc.SelectNodes("//Path");
for(int i=0;i<lst.Count;i++)
{
strs[i] = lst[i].InnerText;
}
using System.IO; int i = 0;
string xml = @"<Files>
<File>
<Path>2007/08/31/200783118012709799872943.jpg</Path>
<Desc>SoftDown</Desc>
<Order>3</Order>
<Size>12 KB</Size>
</File>
<File>
<Path>2007/08/31/200783118012756354308724.jpg</Path>
<Desc>SoftDown</Desc>
<Order>4</Order>
<Size>12</Size>
</File>
<File>
<Path>2007/08/31/200783017719286308162841.jpg</Path>
<Desc>SoftDown</Desc>
<Order>5</Order>
<Size>12 KB</Size>
</File>
</Files>";
XmlDocument xmldoc = new XmlDocument();
StringReader sr = new StringReader(xml);
xmldoc.Load(sr);
XmlNodeList xmllist = xmldoc.SelectNodes("//Files/File");
string[] a = new string [xmllist.Count];
foreach (XmlNode xmlnode in xmllist)
{
a[i] = xmlnode.SelectSingleNode("Path").InnerText;
i++;
}
for (i = 0; i < xmllist.Count; i++)
{
Response.Write(a[i]);
Response.Write("<br />");
}
是这样的么?