- <Object type="System.Windows.Forms.Form, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="P1" children="Controls">
- <Object type="System.Windows.Forms.TextBox,System.Windows.Forms,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" name="loginname" children="Controls">
<Property name="Size">150,21</Property>
<Property name="TabStop">True</Property>
<Property name="Text">用户</Property>
<Property name="TabIndex">0</Property>
<Property name="Name">loginname</Property>
<Property name="Location">170,244</Property>
- <Property name="DataBindings">
<Property name="DefaultDataSourceUpdateMode">OnValidation</Property>
</Property>
</Object>
- <Object type="System.Windows.Forms.TextBox,System.Windows.Forms,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" name="loginpassword" children="Controls">
<Property name="Size">150,21</Property>
<Property name="TabStop">True</Property>
<Property name="Text">密码</Property>
<Property name="TabIndex">1</Property>
<Property name="Name">loginpassword</Property>
<Property name="Location">170,270</Property>
- <Property name="DataBindings">
<Property name="DefaultDataSourceUpdateMode">OnValidation</Property>
</Property>
</Object>
- <Object type="System.Windows.Forms.LinkLabel,System.Windows.Forms,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" name="loginsubmitbutton" children="Controls">
<Property name="Size">74,22</Property>
<Property name="TabStop">True</Property>
<Property name="Text">登录</Property>
<Property name="TabIndex">2</Property>
<Property name="Name">loginsubmitbutton</Property>
<Property name="Location">170,295</Property>
- <Property name="DataBindings">
<Property name="DefaultDataSourceUpdateMode">OnValidation</Property>
</Property>
</Object>
- <Object type="System.Windows.Forms.LinkLabel,System.Windows.Forms,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" name="xzxkAnchor" children="Controls">
<Property name="Size">100,100</Property>
<Property name="TabStop">True</Property>
<Property name="Text">行政许可</Property>
<Property name="TabIndex">3</Property>
<Property name="Name">xzxkAnchor</Property>
<Property name="Location">170,109</Property>
- <Property name="DataBindings">
<Property name="DefaultDataSourceUpdateMode">OnValidation</Property>
</Property>
</Object>
<Property name="ClientSize">1024,768</Property>
</Object>
xml文件如上所示,我要将Property节点下面的name为Location的节点里面的值取出来,改值是一个坐标值,x,y坐标(横,纵坐标)。要求,找出x,y的最小值。怎么遍历?初学xml,不会。各位高手,帮忙!谢谢了!
- <Object type="System.Windows.Forms.TextBox,System.Windows.Forms,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" name="loginname" children="Controls">
<Property name="Size">150,21</Property>
<Property name="TabStop">True</Property>
<Property name="Text">用户</Property>
<Property name="TabIndex">0</Property>
<Property name="Name">loginname</Property>
<Property name="Location">170,244</Property>
- <Property name="DataBindings">
<Property name="DefaultDataSourceUpdateMode">OnValidation</Property>
</Property>
</Object>
- <Object type="System.Windows.Forms.TextBox,System.Windows.Forms,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" name="loginpassword" children="Controls">
<Property name="Size">150,21</Property>
<Property name="TabStop">True</Property>
<Property name="Text">密码</Property>
<Property name="TabIndex">1</Property>
<Property name="Name">loginpassword</Property>
<Property name="Location">170,270</Property>
- <Property name="DataBindings">
<Property name="DefaultDataSourceUpdateMode">OnValidation</Property>
</Property>
</Object>
- <Object type="System.Windows.Forms.LinkLabel,System.Windows.Forms,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" name="loginsubmitbutton" children="Controls">
<Property name="Size">74,22</Property>
<Property name="TabStop">True</Property>
<Property name="Text">登录</Property>
<Property name="TabIndex">2</Property>
<Property name="Name">loginsubmitbutton</Property>
<Property name="Location">170,295</Property>
- <Property name="DataBindings">
<Property name="DefaultDataSourceUpdateMode">OnValidation</Property>
</Property>
</Object>
- <Object type="System.Windows.Forms.LinkLabel,System.Windows.Forms,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" name="xzxkAnchor" children="Controls">
<Property name="Size">100,100</Property>
<Property name="TabStop">True</Property>
<Property name="Text">行政许可</Property>
<Property name="TabIndex">3</Property>
<Property name="Name">xzxkAnchor</Property>
<Property name="Location">170,109</Property>
- <Property name="DataBindings">
<Property name="DefaultDataSourceUpdateMode">OnValidation</Property>
</Property>
</Object>
<Property name="ClientSize">1024,768</Property>
</Object>
xml文件如上所示,我要将Property节点下面的name为Location的节点里面的值取出来,改值是一个坐标值,x,y坐标(横,纵坐标)。要求,找出x,y的最小值。怎么遍历?初学xml,不会。各位高手,帮忙!谢谢了!
解决方案 »
- 正则,正则
- MVC3 中使用jqUploader上传文件的问题!
- 如何获取本机在 Intranet 上的地址?
- 怎样获取当前页面所在的路径对应根目录的路径
- datagrid中每一行使用 checkbox,当checkbox值发生改变时,立即提交到数据库
- ********** Web中实现在即时消息、语音/视频对话、文件传输等功能 ****************
- 百思不得其解,表映射的问题!都来看看
- 请教个GridView显示数据库内容的问题
- 思归:数据库连接如何真正释放?
- html控件和web控件在使用上到底有没有区别?
- 在线急等,再用日期控件时,本该被覆盖着的下拉框控件总是在表层
- 未能加载文件或程序集“NHibernate
你就知道如何选取xml了。
并且所有的Location的x,y 都在原有的数据上面-(x+30), -(y+30)
怎么做?我现在将所有的x写在一个集合里,将y写在一个集合里了。
<?xml version="1.0" encoding="gb2312"?>
<MusicMenu>
<SingerType type="男歌手">
<Singer name="林俊杰">
<Music>江南</Music>
<Music>冻结</Music>
</Singer>
<Singer name="张敬轩">
<Music>断点</Music>
</Singer>
<Singer name="唐磊">
<Music>丁香花</Music>
</Singer>
</SingerType>
<SingerType type="女歌手">
<Singer name="孙燕姿">
<Music>坏天气</Music>
<Music>遇见</Music>
<Music>爱情证书</Music>
</Singer>
<Singer name="范玮琪">
<Music>启程</Music>
<Music>因为</Music>
</Singer>
</SingerType>
</MusicMenu>
C#:
private void BTN_ShowTree_Click(object sender, System.EventArgs e)
{
XmlNodeList nodeListMenu = xmlDoc.SelectSingleNode( "MusicMenu" ).ChildNodes; int indexType = 0;
foreach ( XmlNode nodeType in nodeListMenu )
{
XmlElement elementType = (XmlElement)nodeType;
this.TVW_Menu.Nodes.Add( elementType.GetAttribute("type") ); int indexSinger = 0;
XmlNodeList nodeListSinger = nodeType.ChildNodes;
foreach ( XmlNode nodeSinger in nodeListSinger )
{
XmlElement elementSinger = (XmlElement)nodeSinger;
this.TVW_Menu.Nodes[indexType].Nodes.Add( elementSinger.GetAttribute( "name" ) ); XmlNodeList nodeListMusic = nodeSinger.ChildNodes;
foreach ( XmlNode nodeMusic in nodeListMusic )
{
XmlElement elementMusic = (XmlElement)nodeMusic;
if ( elementMusic.Name == "Music" )
this.TVW_Menu.Nodes[indexType].Nodes[indexSinger].Nodes.Add( elementMusic.InnerText );
}
indexSinger++;
}
indexType++;
}
}
给个例子,自己看看!
{
//for (int i = 0; i < dsoEntity.dsoCtrlList.Count; i++)
//{
// if (dsoEntity.dsoCtrlList[i + 1].hSysObject.Abs_x < dsoEntity.dsoCtrlList[i].hSysObject.Abs_x)
// {
// dsoEntity.dsoCtrlList[i + 1].hSysObject.Abs_x = dsoEntity.dsoCtrlList[i + 1].hSysObject.Abs_x - dsoEntity.dsoCtrlList[i +1].hSysObject.Abs_x + 30;
// dsoEntity.dsoCtrlList[i].hSysObject.Abs_x = dsoEntity.dsoCtrlList[i].hSysObject.Abs_x - dsoEntity.dsoCtrlList[i + 1].hSysObject.Abs_x + 30;
// }
//}
ArrayList arrX = null;
ArrayList arrY = null;
FileStream fs = File.Open("file.xml", FileMode.Open, FileAccess.Read);
StreamReader reader = new StreamReader(fs);
string xml = reader.ReadToEnd();
fs.Close(); XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);
XmlNodeList nodeList = xmlDoc.SelectNodes("/Object/Object");
for (int j = 0; j < nodeList.Count; j++)
{
for (int i = 0; i < dsoEntity.dsoCtrlList.Count; i++)
{
if (dsoEntity.dsoCtrlList[i].ID == nodeList[j].Attributes["name"].Value)
{
for (int k = 0; k < nodeList[j].ChildNodes.Count; k++)
{
if (nodeList[j].ChildNodes[k].Attributes["name"].Value == "Location")
{
string location = nodeList[j].ChildNodes[k].InnerText;
string[] x = location.Split(',');
//dsoEntity.dsoCtrlList[i].hSysObject.Rel_x = int.Parse(x[0]);
//dsoEntity.dsoCtrlList[i].hSysObject.Rel_y = int.Parse(x[1]);
arrX.Add(int.Parse(x[0]));
arrY.Add(int.Parse(x[1]));
}
}
}
}
}
for (int i = 0; i < arrX.Count; i++)
{
if (int.Parse(arrX[i].ToString()) < int.Parse(arrX[i + 1].ToString)))
{
int min = int.Parse(arrX[i].ToString());
arrX[i] = min - (min + 30);
arrX[i + 1] = int.Parse(arrX[i + 1].ToString()) - (min + 30);
}
}
for (int i = 0; i < arrY.Count; i++)
{
if (int.Parse(arrY[i].ToString()) < int.Parse(arrY[i + 1].ToString)))
{
int min = int.Parse(arrY[i].ToString());
arrY[i] = min - (min + 30);
arrY[i + 1] = int.Parse(arrY[i + 1].ToString()) - (min + 30);
}
}
}现在用ArrayList集合保存的所有的坐标值,怎么将改变后的坐标值,在xml中也将其改变?下一步,怎么做?
首先遍历得出所有的location的值,保存到arraylist当中
然后判段得出最小的location,然后再将这个值和arraylist的每个值去比较,满足条件的就重新设置大小,不满足就保存原值。
最后遍历xml将arraylist的新值替换。
{
ArrayList arrX = new ArrayList();
ArrayList arrY = new ArrayList();
XmlDocument xml = new XmlDocument();
xml.Load(FileName);
foreach (XmlNode node in xml.SelectSingleNode("Object").ChildNodes)
{
if (node.ChildNodes.Count > 1)
{
foreach (XmlNode xxNode in node.ChildNodes)
{
if (xxNode.Attributes[0].Value == "Location")
{
string strValue = xxNode.InnerText;
string[] location = strValue.Split(',');
arrX.Add(location[0]);
arrY.Add(location[1]);
break;
} }
}
}
arrX.Sort();
arrY.Sort();
int MinX;
int MinY;
MinX = Convert.ToInt32(arrX[0]);
MinY = Convert.ToInt32(arrY[0]); foreach (XmlNode node in xml.SelectSingleNode("Object").ChildNodes)
{
if (node.ChildNodes.Count > 1)
{
foreach (XmlNode xxNode in node.ChildNodes)
{
if (xxNode.Attributes[0].Value == "Location")
{
string strValue = xxNode.InnerText;
string[] location = strValue.Split(',');
int x = MinX - (MinX + 30);//你的逻辑判断
int y = MinY - (MinY + 30);
xxNode.InnerText = x.ToString() + "," + y.ToString();
break;
} }
}
} xml.Save(FileName);
}
不知道是不是这个意思啊?