首页 > 解决方案 > 在 web 上的 xml 文件中插入数据

问题描述

我正在尝试在我的 xml 文件中的特定标签之间插入数据,该代码在我的计算机上运行良好,但是当我在网络上运行它时,它不会像这样在特定标签之间插入数据:这是我的 xml 文件:

<?xml version='1.0' encoding='utf-8'?>
<rss version='2.0' xmlns:media='http://search.yahoo.com/mrss/'>
<channel>

</channel>
</rss>

我想在“通道”标签内插入数据。这是我的代码,它工作正常!:

FilePath = "h:\root\home\karary-001\www\site1\xmlfile1.xml" **//this is path to my xml file on website**
    Dim document As New XDocument
    document = XDocument.Load(FilePath)
    Dim root = New XElement("item")
    Dim title = New XElement("title", New XCData(TextBox3.Text))
    Dim link = New XElement("link", TextBox6.Text)
    root.Add(title, link)
    document.Root.Elements.First().Add(root)
    document.Save(FilePath)
    Label1.Text = "! done"

当我更改 FilePath ="C:\Users\MONZER\Downloads\XMLFile1.xml" 时:我明白了:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<item>
<title><![CDATA[ title]]></title>
<link>http://karary-001-site1.htempurl.com</link>
<pubDate>2018/08/06 06:20</pubDate>
<description><![CDATA[fsdsdsdsgntbx cfv]]></description>
<media.thumbnail url="http://karary-001-site1.htempurl.com/images/" height="266" width="127" />
</item>
</channel>
</rss>

但是当我使用 FilePath ="h:\root\home\karary-001\www\site1\xmlfile1.xml" 时:我明白了:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
***<channel></channel>***
<item>
<title><![CDATA[ title]]></title>
<link>http://karary-001-site1.htempurl.com</link>
<pubDate>2018/08/06 06:20</pubDate>
<description><![CDATA[fsdsdsdsgntbx cfv]]></description>
<media.thumbnail url="http://karary-001-site1.htempurl.com/images/" height="266" width="127" />
</item>
</rss>

标签: asp.netvb.netvisual-studio

解决方案


推荐阅读