• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

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
0
verintsupport
Asked:
verintsupport
  • 4
  • 3
1 Solution
 
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
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Thanks
0
 
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
 
verintsupportAuthor Commented:
Thank you Dungla!

You really helped me! It's working!

Richard
0
 
dunglaCommented:
:) You're welcome Richard
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now