本文介绍了正在尝试读取列表框中的属性,但没有任何人告诉我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的aspx.cscode ........
this is my aspx.cscode........
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
public partial class xmlread : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnsub_Click(object sender, EventArgs e)
{
XmlTextReader reader = new XmlTextReader("C:\\Documents and Settings\\azhar\\Desktop\\flashrecorder.xml");
XmlNodeType type;
while (reader.Read())
{
type = reader.NodeType;
if (type == XmlNodeType.Element)
{
if (reader.Name == "Name")
{
reader.Read();
TextBox1.Text = reader.Value;
ListBox1.Items.Add(reader.ReadInnerXml());
}
if (reader.Name == "PLAYER_SETTINGS")
{
reader.Read();
if (reader.GetAttribute("Name") == "SiteURL")
{
ListBox1.Items.Add(reader.GetAttribute("SiteURL"));
}
}
}
}
}
}
这是我的xml文件....
this is my xml file....
<?xml version="1.0" encoding="utf-8" ?>
<CONFIG>
<SETTINGS>
<PLAYER_SETTINGS Name="License" Value="6b100nwghzms2cqk8v5prdjyf7t493" />
<PLAYER_SETTINGS Name="SiteURL" Value="http://irrex.ctco.lv:81/videocapture/" />
<PLAYER_SETTINGS Name="ServerURL" Value="rtmp://10.101.101.2:1935/oflaDemo/" />
<PLAYER_SETTINGS Name="FPS" Value="10" />
<PLAYER_SETTINGS Name="AudioRate" Value="11" />
<PLAYER_SETTINGS Name="VideoWidth" Value="320" />
<PLAYER_SETTINGS Name="VideoHeight" Value="240" />
<PLAYER_SETTINGS Name="VideoCompression" Value="85" />
<PLAYER_SETTINGS Name="AudioGain" Value="50" />
<PLAYER_SETTINGS Name="SaveScript" Value="http://irr.ctco.lv/agjbrs/SaveVideoFile.aspx" />
<PLAYER_SETTINGS Name="AudioActivity" Value="50" />
<PLAYER_SETTINGS Name="VideoActivity" Value="50" />
<PLAYER_SETTINGS Name="MaxRecordingTime" Value="50" />
<PLAYER_SETTINGS Name="Color" Value="0x000077" />
<PLAYER_SETTINGS Name="EmbedURL" Value="http://irrex.ctco.lv/videocapture/player.swf" />
<PLAYER_SETTINGS Name="ShareURL" Value="http://irrex.ctco.lv/videocapture/share.aspx" />
<PLAYER_SETTINGS Name="LogoURL" Value="http://irrrx.ctco.lv/videocapture/logo.jpg" />
<PLAYER_SETTINGS Name="RedirectURL" Value="http://irrex.ctco.lv/agjbrs/Videorecorder.aspx?from=save" />
<PLAYER_SETTINGS Name="ShowLinkButton" Value="false" />
</SETTINGS>
<MSG>
<ERROR Name="Saving" Value="Saving file to the database..." />
<ERROR Name="SaveSuccess" Value="The file has been saved successfully" />
<ERROR Name="SaveError" Value="There was an error saving the file.Plz Check File size" />
<ERROR Name="NoMic" Value="You do not have a microphone installed" />
<ERROR Name="NoCam" Value="You do not have a camera installed" />
<ERROR Name="MaxRecordingTime" Value="Time limit" />
</MSG>
</CONFIG>
[edit]已添加代码块-OriginalGriff [/edit]
[edit]Code block added - OriginalGriff[/edit]
推荐答案
XDocument doc = XDocument.Load(@"Your\Path\To\XML\File.xml");
var playerSettingsAttributes = from xml in doc.Element("CONFIG").Elements("SETTINGS").Elements("PLAYER_SETTINGS")
select new
{
Name = xml.Attribute("Name").Value,
Value = xml.Attribute("Value").Value,
};
此示例将为您返回IEnumerable<>具有两个类型(名称和值)属性的匿名类型"
然后,您可以轻松地将其添加到列表或任何其他结构或控件中.
this example will return you an IEnumerable<> with Anonymous Type that have two properties (Name and Value)
Then you can easilly add that into list or any other structure or control.
这篇关于正在尝试读取列表框中的属性,但没有任何人告诉我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!