十六进制值不能包含在名称VB.NET中 [英] Hexadecimal values cannot be included in a name VB.NET
问题描述
我正在尝试编写一个代码来插入现有xml文件中的项目,我希望文件中的项目如下:
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
我收到此错误:
':'字符,十六进制值0x3A,不能包含在名称中。
我尝试了什么:
将ab定义为xnamespace
ab =media:credit然后使用它像:
Dim author = New XElement(ab.tostring,
New XAttribute(role,author),
新的XAttribute(><![CDATA [,TextBox5.Text +]]>))
但是也没有用!
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!
推荐答案
十六进制值不能包含在名称VB.NET中
Hexadecimal values cannot be included in a name VB.NET
没有仔细阅读错误信息!
No read carefully the error message !
':'字符,< b>其十六进制值为0x3A,不能包含在名称中。
The ':' character, which have an hexadecimal value of 0x3A, cannot be included in a name.
字符名称为 column':'
此字符由操作系统保留,不能用于文件名。
The character name is column ':'
This character is reserved by OS and can't be used in a filename.
您正在尝试将元素命名为media:credit。你不能这样做。取出冒号并将元素重命名为其他内容。
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.
这篇关于十六进制值不能包含在名称VB.NET中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!