I am using XmlDocument and XmlNode to manipulate a xml file. Say I want to add a valid node called "Language" to the root, I use such code:
Dim languageNode As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "Language", Nothing)
languageNode.InnerText = "en-US"
root.AppendChild(languageNode)
where xmlDoc is a XmlDocument object and has already been loaded. However, in the xml file after the operation, it appeas like this:
<Language xmlns="">en-US</Language>
And this doesn't pass the validation. Is there anyway to get rid of the namespace? Thanks!
Update: I am editing a .rdlc file, which defines a local report, and using xml format. Part of the file looks like this:
<?xml version="1.0" encoding="utf-16"?>
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition"
xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<Language xmlns="">en-US</Language>
...
Normally there shouldn't be so many namespaces in use but I am generating it from xslt. But the Language node is added after this file is generated. My code looks like this:
Dim xmlRdlc As New XmlDocument()
xmlRdlc.Load(file)
Dim root As XmlNode = xmlRdlc.DocumentElement()
Dim languageNode As XmlNode = xmlRdlc.CreateNode(XmlNodeType.Element, "Language", Nothing)
languageNode.InnerText = "en-US"
root.AppendChild(languageNode)
xmlRdlc.Save(file)
So how should I do to add the desired node like this:
<Language>en-US</Language>