Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi ,I need to split xml files which is having 1000 nodes,but these nodes have namespace( common namespaces ) in it I want to remove the namespaces its making trouble in splitting ,after splitting i want to add in separated files .

Is there any way to split with having namespaces please help
Posted
Comments
Maciej Los 11-Apr-15 14:13pm    
You did not told us what you have tried till now.
parimal2267 12-Apr-15 1:04am    
I split the xml files using this link.,but I am not getting the method to remove the namespaces in xml files


http://www.codeproject.com/Tips/789029/Easy-Method-to-Split-Large-XML-File-Using-LINQ-to

1 solution

Based on the article you referenced: Easy Method to Split Large XML File Using LINQ to XML[^]...

All you need to do is to call RemoveAllNamespaces function passing c1 variable into it:
C#
private static XElement RemoveAllNamespaces(XElement xmlDocument)
   {
       if (!xmlDocument.HasElements)
       {
           XElement xElement = new XElement(xmlDocument.Name.LocalName);
           xElement.Value = xmlDocument.Value;

           foreach (XAttribute attribute in xmlDocument.Attributes())
               xElement.Add(attribute);

           return xElement;
       }
       return new XElement(xmlDocument.Name.LocalName, xmlDocument.Elements().Select(el => RemoveAllNamespaces(el)));
   }


Above function comes from: http://stackoverflow.com/questions/987135/how-to-remove-all-namespaces-from-xml-with-c[^]

I'd call it this way:
C#
XElement frag = new XElement(rootElement, RemoveAllNamespcaes(c1));
 
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