how can i get rid of this field in my XML? xmlns=""

This code is giving me an unknown attrib and i don't understand why?

XmlNode el_folder = m_InPutXml.GetElementsByTagName("Folder")[0];
                  
XmlElement el_placemark = m_InPutXml.CreateElement("Placemark");
el_folder.AppendChild(el_placemark);

result:
<Placemark xmlns="">
</Placemark>

it should be:
<Placemark>
</Placemark>

thanks!

Richard
verintsupportAsked:
Who is Participating?
 
dunglaCommented:
Hi verintsupport,

Sorry, yesterday so busy. Take a look at my code bellow

// load content of file
StreamReader reader = new StreamReader("myXML.xml");
string content = reader.ReadToEnd();
Console.WriteLine(content);

// find the xmlns attribute and remove
string pattern = @"\s+xmlns="+ "\"" + "(\\w+)\"";
content = Regex.Replace(content, pattern, string.Empty, RegexOptions.IgnoreCase);

XmlDocument m_InPutXml = new XmlDocument();
// load xml
m_InPutXml.LoadXml(content);
XmlNode el_folder = m_InPutXml.GetElementsByTagName("Folder")[0];

XmlElement el_placemark = m_InPutXml.CreateElement("Placemark");
el_folder.AppendChild(el_placemark);
Console.WriteLine(m_InPutXml.InnerXml);
0
 
dunglaCommented:
Hi verintsupport,

Can you paste the original XML file?
0
 
verintsupportAuthor Commented:
Thanks dungla

Following your request, i noticed that this file has a xmlns="xxx" attrib in the root. (see below)

How could i remove it?

Thanks

Richard

----------Original XML-------------------
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="xxx">
  <Document>
    <name>5510.kml</name>
    <Folder>
      <name>5510</name>
      <open>1</open>
    </Folder>
  </Document>
</kml>

----------RESULT-------------------
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="xxx">
  <Document>
    <name>5510.kml</name>
    <Folder>
      <name>5510</name>
      <open>1</open>
      <Placemark xmlns="">
        <name>5510</name>
        <LineString>
          <altitudeMode>xxx</altitudeMode>
          <coordinates>xxx</coordinates>
        </LineString>
        <tessellate>1</tessellate>
        <description><![CDATA[<Verint><NextMod>S1100</NextMod></Verint>]]></description>
      </Placemark>
    </Folder>
  </Document>
</kml>
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
verintsupportAuthor Commented:
I forgot to wirte that by removing it manually... it doent create this attrib anymore.

How could i remove it easilly when reading the file?  I don't need it...  


i'm very new to c#


Thanks

Richard
0
 
verintsupportAuthor Commented:
Is there a way to edit the XML as a text file before reading it as an XML?

Thanks
0
 
verintsupportAuthor Commented:
Thank you Dungla!

You really helped me! It's working!

Richard
0
 
dunglaCommented:
:) You're welcome Richard
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.