【发布时间】:2017-03-05 19:21:07
【问题描述】:
我需要使用 VP.Net 在XML 文件中为Xmlns 添加属性,我使用了以下代码:
Dim ns As XNamespace = "http://www.sitemaps.org/schemas/sitemap/0.9"
Dim xi As XNamespace = "http://www.w3.org/1999/xhtml"
Dim doc As New XmlDocument
Dim decNode As XmlNode = doc.CreateXmlDeclaration("1.0", "utf-8", Nothing)
doc.AppendChild(decNode)
Dim parentNode As XmlNode
parentNode = doc.CreateElement("xmlns")
doc.AppendChild(parentNode)
Dim childNode1 As XmlNode = doc.CreateElement("url")
parentNode.AppendChild(childNode1)
Dim sitemap_loc As String = "https://example.com/" & "example.aspx?tdc_id=" & dtvTender.Table.Rows(tender).Item(CMS_Tender_Category.Fields.TDC_ID)
Dim sitemap_lastmod As String = Date.Now.ToString("yyyy-MM-dd")
Dim childElement1 As XmlElement = doc.CreateElement("loc")
childElement1.InnerText = sitemap_loc
childNode1.AppendChild(childElement1)
Dim childElement2 As XmlElement = doc.CreateElement("lastmod")
childElement2.InnerText = sitemap_lastmod
childNode1.AppendChild(childElement2)
Dim strfilepath As String = Server.MapPath("~/SiteMap/") & Date.Now.ToString("dd-MM-yyyy") & ".xml"
doc.Save(strfilepath)
我需要在xmlns标签内添加这个属性
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml
【问题讨论】:
标签: asp.net xml vb.net sitemap