':'字符,十六进制值0x3A,不能包含在名称中'''字符,十六进制值0x3A,不能包含在名称中 [英] The ':' character, hexadecimal value 0x3A, cannot be included in a nameThe ':' character, hexadecimal value 0x3A, cannot be included in a name

查看:190
本文介绍了':'字符,十六进制值0x3A,不能包含在名称中'''字符,十六进制值0x3A,不能包含在名称中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写要插入的代码在存在XML文件中的项目,我想在文件中的项是这样的:


<预类= "x_x_default x_x_prettyprint x_x_prettyprinted" 风格="填充:5px的;边界宽度:0像素;边框样式family:宋体;边框颜色family:宋体;的line-height:继承; FONT-FAMILY:索拉,门罗,摩纳哥, '龙力控制台', '解放单声道', '幻觉记忆国界单','档案维拉国界单','Courier New',monospace,sans-serif; font-size:13px; vertical-align:baseline; width:auto; max-height:600px; background-color:#eff0f1; color:#393318;自动换行:normal"> < item>
< title> <![CDATA [any title]]> < / title>
< link> http://任何链接 < / link>
< pubDate> 任何日期 < / pubDate>
< guid isPermaLink = " true" > 任何链接 < / guid>
< description> <![CDATA [any description]]> < / description>
< media:credit 角色 = " author" > <![CDATA [任何作者]]> < / media:credit>
< media:category> <![CDATA [任何类别]]> < / media:category>
< media:content 网址 = " http:// any link" 身高 = " 266" 宽度 = " 127" />
< media:thumbnail 网址 = " http:// any link" 身高 = " 266" 宽度 = " 127" />
< / item>

所以我写了这段代码:


    

Dim FilePath As String

&NBSP;&NBSP;&NBSP;&NBSP;文件路径= QUOT; C:\Users\MONZER\Desktop\Karary网络Site\WebApplication1\XMLFile1.xml"

&NBSP;     Dim document As New XDocument

     If File.Exists(FilePath)Then then
     ;   document = XDocument.Load(FilePath)

     Else

       Label1.Text =" not done"

    结束如果



      ;昏暗根=新的XElement(QUOT;项目")

&NBSP;&NBSP;&NBSP;&NBSP;昏暗标题=新的XElement(QUOT;标题","<![CDATA ["&安培; TextBox3.Text&"]]>")

     Dim link = New XElement(" link" ,TextBox6.Text)

  &NBSP; &NBSP; &NBSP; Dim pubDate = New XElement(" pubDate",DateTime.Now.ToString(" yyy / MM / dd HH:mm")))
  &NBSP; &NBSP; &NBSP; Dim description = New XElement(" description",TextBox5.Text)

  &NBSP; &NBSP; &NBSP;昏暗的作家=新的XElement("介质:信用" ;,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;新XAttribute("作用","作者"),

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;新XAttribute(QUOT;><![CDATA [" ;, TextBox5.Text + QUOT;]]>"))



  &NBSP; &NBSP; &NBSP; root.Add(title,link,pubDate,description,author)

  &NBSP; &NBSP; &NBSP; document.Root.Add(root)

  &NBSP; &NBSP; &NBSP; document.Save(FilePath)

  &NBSP; &NBSP; &NBSP; Label1.Text =" done"



  &NBSP;结束子



我收到此错误:
':' 字符,十六进制值0x3A,不能包含在一个名称

解决方案

您无法命名元素< media :cateogry>等&NBSP;该错误告诉您这不是XML元素名称中的有效字符。


为什么不简单地创建< media>元素,然后把< category>,< content>和< thumbnail>作为子元素?


另一种选择是用有效字符(如下划线)替换冒号。


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.

解决方案

You can't name an element <media:cateogry> etc.  The error is telling you that is not a valid character in an XML element name.

Why not simply create a <media> element and then put <category>, <content>, and <thumbnail> as child elements?

Another option would be to replace the colon with a valid character such as underscore.


这篇关于':'字符,十六进制值0x3A,不能包含在名称中'''字符,十六进制值0x3A,不能包含在名称中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆