|
I must be slipping. This used to work...
The XML file:
<?xml version="1.0" encoding="utf-8"?>
<Properties>
<PropertyEditor>
<Property ViewName = "Characteristics" PropertyName = "ValueLand" DisplayName = "Land Value" DataType = "numeric"/>
<Property ViewName = "Characteristics" PropertyName = "ValueStructure" DisplayName = "Structure Value" DataType = "numeric"/>
<Property ViewName = "Characteristics" PropertyName = "ValuePersonal" DisplayName = "Personal Value" DataType = "numeric"/>
</PropertyEditor>
</Properties>
and the code to read it
private void GetPropertyData()
{
propertyDatas = new List<PropertyData>();
string path = Path.GetDirectoryName(Application.ExecutablePath) + @"\EditorProperties.xml";
XmlTextReader reader = new XmlTextReader(path);
XmlDocument doc = new XmlDocument();
XmlNode node = doc.ReadNode(reader);
foreach (XmlNode childNode in node.ChildNodes)
{
foreach (XmlAttribute att in childNode.Attributes)
{
PropertyData propertyData = new PropertyData
{
ViewName = att.Attributes["Characteristics"].Value,
PropertyName = att.Attributes["PropertyName"].Value,
DisplayName = att.Attributes["DisplayName"].Value,
DataType = att.Attributes["numeric"].Value
};
propertyDatas.Add(propertyData);
}
}
}
Now, for some reason, it reads the 'XML' line, then the code skips out on the first foreach.
What's wrong here?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Kevin Marois wrote: What's wrong here?
I cannot say whether or not this used to work; but when debugging, it tries to iterate the children of the first element. The first element being the <xml> tag, and it has no children.
XmlTextReader reader = new XmlTextReader(path);
XmlDocument doc = new XmlDocument();
reader.MoveToContent();
XmlNode node = doc.ReadNode(reader);
http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.movetocontent.aspx[^]
|
|
|
|
|
That's exactly what I said in my post.
If it's not broken, fix it until it is
|
|
|
|
|
Kevin Marois wrote: That's exactly what I said in my post.
In that case, it would have been a duplicate. Did you do any updates? (Software-updates, VS, Automated Updates, MSXML?)
Could it be that your Xml "used" to simply not have the first line in there? In that case, the code would have worked, as is.
modified 5-Nov-12 16:59pm.
|
|
|
|
|
Somehow got your attribute names screwed up:
PropertyData propertyData = new PropertyData();
{
propertyData.ViewName = childNode.Attributes["ViewName"].Value;
propertyData.PropertyName = childNode.Attributes["PropertyName"].Value;
propertyData.DisplayName = childNode.Attributes["DisplayName"].Value;
propertyData.DataType = childNode.Attributes["DataType"].Value;
};
|
|
|
|