Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi people,

I have made suitable changes and saved a file as .xml .

Wheni open the file by XElement , it adds unwanted precedings to each node , by which

im not able to loop through each node by IEnumerable.

Pls help.

The code is :

XML
StreamReader stmReader = new StreamReader(flNameIs);
                String xsltData = stmReader.ReadToEnd();
                xsltData = xsltData.Replace("xsl:", "");
                xsltData="<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>"+xsltData;
                stmReader.Close();
                StreamWriter writer = new StreamWriter(tempFlName);
                writer.Write(xsltData);
                writer.Flush();
                writer.Close();
                XElement doc = XElement.Load(tempFlName);
            doc.RemoveAnnotations
               IEnumerable<XElement> e1 =from match in doc.Descendants("stylesheet").Descendants("template") select match;



While reading the file , it adds a text "n1: " to each node starting point.

Kindly help.
Posted
Updated 23-Apr-12 4:01am
v2
Comments
BobJanova 23-Apr-12 8:44am    
What are the actual contents of the file?

1 solution

Unless the contents of the xml file are seen, it is difficult to figure out the cause for addition of n1: specified in the question. But, it appears from the question description that the reason may be due to the addition of name space to the element and in this regard the following references may be helpful.
http://stackoverflow.com/questions/1231396/xelement-default-namespace-on-attributes-provides-unexpected-behaviour[^]
http://msdn.microsoft.com/en-us/library/bb387075.aspx[^]
http://stackoverflow.com/questions/1453564/how-to-addor-ignore-xml-namespace-when-using-xelement-load[^]
 
Share this answer
 
Comments
Abhinav S 23-Apr-12 23:18pm    
Good references. 5.
VJ Reddy 23-Apr-12 23:34pm    
Thank you, Abhinav.
I think the vote is not updated.
Abhinav S 24-Apr-12 2:56am    
Oops fixed now.
VJ Reddy 24-Apr-12 3:04am    
Thank you, Abhinav.

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