Dim xmlDoc As New XmlDocument()
xmlDoc.Load(Server.MapPath("sitemap.xml"))
Dim subRoot As XmlElement = xmlDoc.CreateElement("url")
Dim appendedElementUsername As XmlElement = xmlDoc.CreateElement("loc")
Dim xmlTextUserName As XmlText = xmlDoc.CreateTextNode("p2")
appendedElementUsername.AppendChild(xmlTextUserName)
subRoot.AppendChild(appendedElementUsername)
xmlDoc.DocumentElement.AppendChild(subRoot)
xmlDoc.Save(Server.MapPath("sitemap.xml"))
You need to pass in the root node's namespace when creating any child node you want not to have a prefix on.
Using a namespace without a prefix at the root means that you need to use that same namespace on child elements for them to also not have prefixes.
You need to modify the below lines in your code
Dim subRoot As XmlElement = xmlDoc.CreateElement("url", "http://www.sitemaps.org/schemas/sitemap/0.9")
Dim appendedElementUsername As XmlElement = xmlDoc.CreateElement("loc", "http://www.sitemaps.org/schemas/sitemap/0.9")
Your revised method
Dim xmlDoc As New XmlDocument()
xmlDoc.Load(Server.MapPath("sitemap.xml"))
Dim subRoot As XmlElement = xmlDoc.CreateElement("url", "http://www.sitemaps.org/schemas/sitemap/0.9")
Dim appendedElementUsername As XmlElement = xmlDoc.CreateElement("loc", "http://www.sitemaps.org/schemas/sitemap/0.9")
Dim xmlTextUserName As XmlText = xmlDoc.CreateTextNode("p2")
appendedElementUsername.AppendChild(xmlTextUserName)
subRoot.AppendChild(appendedElementUsername)
xmlDoc.DocumentElement.AppendChild(subRoot)
xmlDoc.Save(Server.MapPath("sitemap.xml"))
Member
151 Points
473 Posts
Insert to XML file
Sep 26, 2013 11:33 AM|mehr_83|LINK
Hi,
my XML file is:
and i use this code for insert:
but, in insert xmlns="" added to <url> :
I do not add xmlns="" to <url>,
How i do?
Please help me.
All-Star
50831 Points
9895 Posts
Re: Insert to XML file
Sep 26, 2013 11:51 AM|A2H|LINK
Hi,
You need to pass in the root node's namespace when creating any child node you want not to have a prefix on.
Using a namespace without a prefix at the root means that you need to use that same namespace on child elements for them to also not have prefixes.
You need to modify the below lines in your code
Your revised method
Aje
My Blog | Dotnet Funda
Member
151 Points
473 Posts
Re: Insert to XML file
Sep 26, 2013 11:57 AM|mehr_83|LINK
Thanks a lot,
This is work.