Click here to Skip to main content
15,921,250 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm trying to insert data between specific tag inside my xml file , The code works well on my computer but when I run it on the web it Does not insert the data between the specific tag like that : this is my xml file :
<?xml version='1.0' encoding='utf-8'?>
<rss version='2.0' xmlns:media='http://search.yahoo.com/mrss/'>
<channel>

</channel>
</rss>

I want to insert data inside "channel" tag . this is my code it's working fine ! :
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"

when I change FilePath ="C:\Users\MONZER\Downloads\XMLFile1.xml" : I get this :
<?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>

but when I use FilePath ="h:\root\home\karary-001\www\site1\xmlfile1.xml" : I get this :
<?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>


What I have tried:

change the file extensions to txt and change the code to :
dim channelNode = document.Root.Descendants("channel").FirstOrDefault
channelNode.Add(root)
Posted
Comments
Eric Lynch 6-Aug-18 12:59pm    
If everything is truly as stated, I don't see how this is possible. I think maybe you have missed some small difference between the two input files you are using in your test.

I would try the following experiment. Temporarily rename the input file that doesn't work. Copy the input file that does work to that same location. Re-try your test.

At this point, I would be shocked if you don't get the correct result in both cases. Then, if you need to debug the difference, get a hex dump and compare the working and non-working files byte for byte.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900