Click here to Skip to main content
15,897,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So i'm working on a project to parse lots of xml files and extract 6 values from them I think the easiest is using linq to xml.
Here is what the xml looks like: ( the '<' '>' around all values have been taken out by editor.)

XAxisCalib
Max 288.93 Max
Min-48.08 Min
HTML
<maxs>200</maxs>           
<dftht>0</dftht>           
<ldve>0</ldve>           
<ejve>0</ejve>


YAxisCalib
Max 646.01/Max
Min-90.9/Min
HTML
<maxs>200</maxs>           
<dftht>0</dftht>           
<ldve>0</ldve>          
 <ejve>0</ejve>         
<yaxiscalib> </yaxiscalib>

ZAxisCalib
Max 16.1 Max
Min-146.82 Min

I need to extract form the files the max and min of each x,y,and z calib.
Anyone help with this?

I have this example but how do I manipulate it to extract those 6 values. I only want those values and I want to save them to a file not display on screen

C#
string file = @"c:\file.xml";  
XDocument doc = XDocument.Load(file);   
int i = 0;   
var result = from ele in doc.Descendants()                    
             where ele.HasElements == false //read leaf node                       
             select new{ ParentName=ele.Parent.Name, Name=ele.Name , Value=ele.Value };  

foreach (var ele in result )     
{          
    Console.WriteLine(ele.ParentName + " " + ele.Name + " " + ele.Value);    
}
Posted
Updated 2-Sep-11 5:18am
v2
Comments
#realJSOP 2-Sep-11 11:18am    
I reformatted the best I could, but your example xml is messed up.

The first thing I see is that your new statement is junk. It should be something like this:

C#
var result = from ele in doc.Descendants()
             where ele.HasElements == false //read leaf node
             select new SomeObject(){ ParentName=ele.Parent.Name, Name=ele.Name , Value=ele.Value };


The second thing I see is the use of var in your foreach statement. Just use the correct type. It's much more efficient.

Finally, I recommend that you use complete words for variable names. It makes your code a LOT easier to read.
 
Share this answer
 
Could I do something like this for the xaxis calib 'max' and then repeat for 'min' then change it ycalib max and min then zcalib max and min.

string file = @"c:\ScicloneUAC.xml";
XDocument doc = XDocument.Load(file);
int i = 0;
var result = from ele in doc.Descendant(XAxisCalib)
where ele.HasElements == false

select new { Max=ele."Max".value, };
foreach (var ele in result ) {
Console.WriteLine(ele."Max".+" ");
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900