private List<customPair> readXML(string myXMLFile)
{
List<customPair> myList = new List<customPair>();
if (string.IsNullOrEmpty(myXMLFile))
{
return myList;
}
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.IgnoreWhitespace = true;
// Create a resolver with default credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;
readerSettings.XmlResolver = resolver;
DateTime myMissingDate = DateTime.Parse("01-01-0001 00:00:00");
XmlReader reader = null;
XmlReader myPartSubtree = null;
try
{
reader = XmlReader.Create(myXMLFile, readerSettings);
string myTempName = "";
do
{
if (reader.Name == "job_layer")
{
do
{
customPair cp = new customPair();
if (reader.Name == "name")
{
reader.Read();
if (reader.Value != "")
{
myTempName = reader.Value;
cp.item_name = myTempName;
}
else
{
cp.item_name = "";
}
}
else if (reader.Name == "part")
{
cp.item_name = myTempName;
myPartSubtree = reader.ReadSubtree();
myPartSubtree.ReadToFollowing("index");
myPartSubtree.Read();
cp.part_index = Int32.Parse(myPartSubtree.Value);
myPartSubtree.ReadToFollowing("t_start");
myPartSubtree.Read();
cp.part_tstart = DateTime.Parse(myPartSubtree.Value);
myPartSubtree.ReadToFollowing("t_end");
myPartSubtree.Read();
cp.part_tend = DateTime.Parse(myPartSubtree.Value);
myPartSubtree.ReadToFollowing("process");
myPartSubtree.Read();
cp.part_process = Int32.Parse(myPartSubtree.Value);
myPartSubtree.ReadToFollowing("result");
myPartSubtree.Read();
cp.part_result = Int32.Parse(myPartSubtree.Value);
myPartSubtree.ReadToFollowing("alignment_scale");
cp.part_align_scale_x = float.Parse(reader.GetAttribute(0), CultureInfo.InvariantCulture);
cp.part_align_scale_y = float.Parse(reader.GetAttribute(1), CultureInfo.InvariantCulture);
cp.part_align_scale_z = float.Parse(reader.GetAttribute(2), CultureInfo.InvariantCulture);
myPartSubtree.ReadToFollowing("alignment_offset");
cp.part_align_offset_x = float.Parse(reader.GetAttribute(0), CultureInfo.InvariantCulture);
cp.part_align_offset_y = float.Parse(reader.GetAttribute(1), CultureInfo.InvariantCulture);
cp.part_align_offset_z = float.Parse(reader.GetAttribute(2), CultureInfo.InvariantCulture);
myPartSubtree.ReadToFollowing("alignment_angle_cw");
myPartSubtree.Read();
cp.part_align_angle = double.Parse(myPartSubtree.Value, CultureInfo.InvariantCulture);
myPartSubtree.Close();
}
if ((!String.IsNullOrEmpty(cp.item_name)) && (cp.part_tstart != myMissingDate) && (cp.part_tend != myMissingDate))
{
myList.Add(cp);
}
} while (reader.Read());
}
} while (reader.Read());
}
catch (FileNotFoundException ex)
{
Console.WriteLine(ex.Message);
}
// specjalnie dla win2k
catch (IOException ioex)
{
Console.WriteLine(ioex.Message);
}
finally
{
// close handle
if (myPartSubtree != null)
{
myPartSubtree.Close();
}
if (reader != null)
{
// Console.WriteLine(reader.ReadState);
reader.Close();
}
}
return myList;
}