Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to write a code to insert items in exist xml file ,I want the items in file to be like this:
<item>
  <title><![CDATA[any title]]></title>
  <link>http://any link</link>
  <pubDate>any date</pubDate>
  <guid isPermaLink="true">any link</guid>
  <description><![CDATA[any description]]></description>
        <media:credit role="author"><![CDATA[any author]]></media:credit>
  <media:category><![CDATA[any category]]></media:category>
  <media:content url="http://any link" height="266" width="127" /> 
  <media:thumbnail url="http://any link" height="266" width="127" />
</item>

so I have write this code :
Dim FilePath As String
        FilePath = "C:\Users\MONZER\Desktop\Karary Web Site\WebApplication1\XMLFile1.xml"
        Dim document As New XDocument
        If File.Exists(FilePath) Then
            document = XDocument.Load(FilePath)
        Else
            Label1.Text = "not done"
        End If

        Dim root = New XElement("item")
        Dim title = New XElement("title", "<![CDATA[" & TextBox3.Text & "]]>")
        Dim link = New XElement("link", TextBox6.Text)
        Dim pubDate = New XElement("pubDate", DateTime.Now.ToString("yyy/MM/dd HH:mm"))
        Dim description = New XElement("description", TextBox5.Text)
        Dim author = New XElement("media:credit",
                                      New XAttribute("role", "author"),
                                      New XAttribute("><![CDATA[", TextBox5.Text + "]]>"))

        root.Add(title, link, pubDate, description, author)
        document.Root.Add(root)
        document.Save(FilePath)
        Label1.Text = "done"

    End Sub

I got this error :
The ':' character, hexadecimal value 0x3A, cannot be included in a name.

What I have tried:

define ab as xnamespace
ab="media:credit" then use it like :
Dim author = New XElement(ab.tostring,
New XAttribute("role", "author"),
New XAttribute("><![CDATA[", TextBox5.Text + "]]>"))
but did not work either!
Posted
Updated 19-Jul-18 9:03am

Quote:
Hexadecimal values cannot be included in a name VB.NET

No read carefully the error message !
Quote:
The ':' character, which have an hexadecimal value of 0x3A, cannot be included in a name.

The character name is column ':'
This character is reserved by OS and can't be used in a filename.
 
Share this answer
 
You're trying to name an element "media:credit". You can't do that. Take the colon out and rename the element to something else.
 
Share this answer
 

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