xml文件中的参数如何用C# 语言读出????
<?xmlversion="1.0"encoding="utf-8"?><vgversion="700"gridsize="4"range="0,0,1024,768"b...
<?xml version="1.0" encoding="utf-8"?>
<vg version="700" gridsize="4" range="0,0,1024,768" bordericons="7" borderstyle="1" scrollbars="3" windowstate="0" backcolor="$FFFFFF">
<page name="page" bounds="0,0,793.700787,1122.141732" visible="false" margin="100,100,100,100" paperwidth="2100" paperheight="2969"/>
<sheet name="sheet1">
<母线6041 name="母线60411" bounds="140,96,242,96" origin="191,96" CloneFlag="false" DevColor="255" DevID="0" DevNo="'Ⅰ母'" DevType="0" EleClass="'设备组'" GrdColor="0" GrpTypeID="6041" NoInfoFlag="false" StaGrpID="0" StaID="9" VLevel="3">
<参数 name="组内参数1" bounds="241,91,270.077882,107" origin="255.538941,99" locked="true" BackColor="16777215" BackVisiual="false" DevColor="255" DevGrpEleID="1" DevID="0" DevType="0" EleClass="'基本参数'" FontSize="12" GrpEleTypeName="'参数'" ParamType="0" ParamTypeName="'显示编号'" ParamValue="'Ⅰ母'" StaID="0">
<text name="text1" bounds="241,91,271,107" origin="245,98" linecolor="$FF" autosize="true" border="$0" fontname="宋体" fontsize="12" fontbold="true" fontcolor="$FF" textalign="0" text="Ⅰ母"/>
<programe>
property BackColor read GetBackColor write SetBackColor editor Color
property BackVisiual read GetBackVisiual write SetBackVisiual editor Bool
property FontColor read GetFontColor write SetFontColor editor Color
property FontSize read GetFontSize write SetFontSize editor FontSize
private function GetBackColor()
return text1.BackColor
end function
private function GetBackVisiual()
return Cur_BVisiual
end function
private function GetFontColor()
return text1.FontColor
end function
比如我想读bounds 这个参数的值怎么读??? 展开
<vg version="700" gridsize="4" range="0,0,1024,768" bordericons="7" borderstyle="1" scrollbars="3" windowstate="0" backcolor="$FFFFFF">
<page name="page" bounds="0,0,793.700787,1122.141732" visible="false" margin="100,100,100,100" paperwidth="2100" paperheight="2969"/>
<sheet name="sheet1">
<母线6041 name="母线60411" bounds="140,96,242,96" origin="191,96" CloneFlag="false" DevColor="255" DevID="0" DevNo="'Ⅰ母'" DevType="0" EleClass="'设备组'" GrdColor="0" GrpTypeID="6041" NoInfoFlag="false" StaGrpID="0" StaID="9" VLevel="3">
<参数 name="组内参数1" bounds="241,91,270.077882,107" origin="255.538941,99" locked="true" BackColor="16777215" BackVisiual="false" DevColor="255" DevGrpEleID="1" DevID="0" DevType="0" EleClass="'基本参数'" FontSize="12" GrpEleTypeName="'参数'" ParamType="0" ParamTypeName="'显示编号'" ParamValue="'Ⅰ母'" StaID="0">
<text name="text1" bounds="241,91,271,107" origin="245,98" linecolor="$FF" autosize="true" border="$0" fontname="宋体" fontsize="12" fontbold="true" fontcolor="$FF" textalign="0" text="Ⅰ母"/>
<programe>
property BackColor read GetBackColor write SetBackColor editor Color
property BackVisiual read GetBackVisiual write SetBackVisiual editor Bool
property FontColor read GetFontColor write SetFontColor editor Color
property FontSize read GetFontSize write SetFontSize editor FontSize
private function GetBackColor()
return text1.BackColor
end function
private function GetBackVisiual()
return Cur_BVisiual
end function
private function GetFontColor()
return text1.FontColor
end function
比如我想读bounds 这个参数的值怎么读??? 展开
1个回答
展开全部
读xml文件中的某一个参数的值,也要分析整个xml文件,没有可以直接指定读某个值的,建义你可以将这个xml的文件先读取程序中用数组或其它的方法保存起来,并建立一种索引机制就行了,至于读xml的方法,你可以参考下面这段程序:
public XMLOperate(string xmlFileName, string nodeRootsName)
{
#region 文件读取,并看文件是否符合要求
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
try
{
doc.Load(xmlFileName);
}
catch (System.Exception e1)
{
this.err = "读取文件失败!\n"+e1.Message;
return;
}
System.Xml.XmlNodeList nodeRoots = doc.GetElementsByTagName(nodeRootsName);//与之相配的节点数
if (nodeRoots.Count == 0)
{
string sErr = "格式不对,请用标准的格式文件编写!\n";
err = sErr;
return;
}
#endregion 文件读取完成
#region 读取文件的分类
System.Xml.XmlNode nodeRoot = nodeRoots[0];//第一级子目录
try
{
for (int i = 0; i < nodeRoot.ChildNodes.Count; i++)
{
System.Xml.XmlNode nodeSecond = nodeRoot.ChildNodes[i];//第二级目录
if (nodeSecond.NodeType == System.Xml.XmlNodeType.Element) //类型
{
switch (nodeSecond.Name.ToLower().Trim())//取相应的名字
{
case "name1":
//测试用
this.name = nodeSecond.Attributes.GetNamedItem("name").Value.ToString();
this.dbIndex = int.Parse(nodeSecond.Attributes.GetNamedItem("Index").Value.ToString());
this.dbdCount = int.Parse(nodeSecond.Attributes.GetNamedItem("Count").Value.ToString());
//测试完
this.blockReads.Add(new BlockRead(nodeSecond));
break;
case "name2":
this.name = nodeSecond.Attributes.GetNamedItem("name").Value.ToString();
this.dbIndex = int.Parse(nodeSecond.Attributes.GetNamedItem("Index").Value.ToString());
this.dbdCount = int.Parse(nodeSecond.Attributes.GetNamedItem("Count").Value.ToString());
this.blockWrites.Add(new BlockWrite(nodeSecond));
break;
default:
break;
}
}
}
}
public XMLOperate(string xmlFileName, string nodeRootsName)
{
#region 文件读取,并看文件是否符合要求
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
try
{
doc.Load(xmlFileName);
}
catch (System.Exception e1)
{
this.err = "读取文件失败!\n"+e1.Message;
return;
}
System.Xml.XmlNodeList nodeRoots = doc.GetElementsByTagName(nodeRootsName);//与之相配的节点数
if (nodeRoots.Count == 0)
{
string sErr = "格式不对,请用标准的格式文件编写!\n";
err = sErr;
return;
}
#endregion 文件读取完成
#region 读取文件的分类
System.Xml.XmlNode nodeRoot = nodeRoots[0];//第一级子目录
try
{
for (int i = 0; i < nodeRoot.ChildNodes.Count; i++)
{
System.Xml.XmlNode nodeSecond = nodeRoot.ChildNodes[i];//第二级目录
if (nodeSecond.NodeType == System.Xml.XmlNodeType.Element) //类型
{
switch (nodeSecond.Name.ToLower().Trim())//取相应的名字
{
case "name1":
//测试用
this.name = nodeSecond.Attributes.GetNamedItem("name").Value.ToString();
this.dbIndex = int.Parse(nodeSecond.Attributes.GetNamedItem("Index").Value.ToString());
this.dbdCount = int.Parse(nodeSecond.Attributes.GetNamedItem("Count").Value.ToString());
//测试完
this.blockReads.Add(new BlockRead(nodeSecond));
break;
case "name2":
this.name = nodeSecond.Attributes.GetNamedItem("name").Value.ToString();
this.dbIndex = int.Parse(nodeSecond.Attributes.GetNamedItem("Index").Value.ToString());
this.dbdCount = int.Parse(nodeSecond.Attributes.GetNamedItem("Count").Value.ToString());
this.blockWrites.Add(new BlockWrite(nodeSecond));
break;
default:
break;
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询