不能使用& amp;作为属性值 [英] Cannot use & as an attribute value

查看:66
本文介绍了不能使用& amp;作为属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个独立的XML文件(带有相应的xml文档标题)

当我使用XmlDocument加载它时工作正常。我可以有这样的子元素

没有问题:


< SomeChildElement type =" c" HREF =" There.aspx ID = 5英寸/>


但是,只要我将其更改为以下内容:


< SomeChildElement type =" c" HREF =" There.aspx ID = 5&放大器;放大器; T = M" />


我得到一个XML Exception,表明它是预期的引用(或类似

那样)。我以为& amp; amp;是一个国际实体,总是可以使用
。或者它只能用作InnerText的一部分但不能用作属性?

如何解决这个问题?


谢谢,

Emilio

Hi,
I have a standalone XML file (with the appropriate xml document header)
that works fine when I load it using XmlDocument. I can have child elements
like this without problems:

<SomeChildElement type="c" href="There.aspx?id=5" />

But as soon as I change it to something like this:

<SomeChildElement type="c" href="There.aspx?id=5&amp;t=m" />

I get an XML Exception indicating that it expected quote (or something like
that). I thought the &amp; was an internatl entity that could always be
used. Or can it only be used as part of an InnerText but not an Attribute?
How can I resolve that problem?

Thanks,
Emilio

推荐答案

这是我得到的错误:


加载XML系统时出错。 Xml.XmlException:这是一个意外的

令牌。预期的标记是''SEMICOLON''。第14行,第32位。

System.Xml.XmlScanner.ScanNamedEntity()at

System.Xml.XmlTextReader.ExpandLiteral(XmlAttribut eTokenInfo currToken)

System.Xml.XmlTextReader.SetLiteralValues(XmlAttri buteTokenInfo fld)at

System.Xml.XmlTextReader.SetAttributeValues()at

System.Xml.XmlTextReader.ParseElement ()at System.Xml.XmlTextReader.Read()

at System.Xml.XmlValidatingReader.ReadNoCollectText to ken()at

System.Xml.XmlValidatingReader.Read()at

System.Xml.XmlLoader.LoadCurrentNode()at

System.Xml.XmlLoader.LoadChildren(XmlNode parent)

System.Xml。 XmlLoader.LoadElementNode()at

System.Xml.XmlLoader.LoadCurrentNode()at

System.Xml.XmlLoader.LoadCurrentNode()at

System.Xml.XmlLoader.LoadChildren(XmlNode parent)

System.Xml.XmlLoader.LoadElementNode()at

System.Xml.XmlLoader.LoadCurrentNode()at the br />
System.Xml.XmlLoad在System.Xml.XmlDocument.Load上的er.LoadDocSequence(XmlDocument parentDoc)

System.Xml.XmlLoader.Load(XmlDocument doc,XmlReader reader,Boolean

preserveWhitespace)(

System.Xml.XmlDocument.LoadXml(String xml)at

" ~~~ .NET Ed ~~~" < TI ********* @ abolishspam.now>写在留言中

新闻:%2 **************** @ tk2msftngp13.phx.gbl ...
This is the error I get:

Error While loading XML System.Xml.XmlException: This is an unexpected
token. The expected token is ''SEMICOLON''. Line 14, position 32. at
System.Xml.XmlScanner.ScanNamedEntity() at
System.Xml.XmlTextReader.ExpandLiteral(XmlAttribut eTokenInfo currToken) at
System.Xml.XmlTextReader.SetLiteralValues(XmlAttri buteTokenInfo fld) at
System.Xml.XmlTextReader.SetAttributeValues() at
System.Xml.XmlTextReader.ParseElement() at System.Xml.XmlTextReader.Read()
at System.Xml.XmlValidatingReader.ReadNoCollectTextTo ken() at
System.Xml.XmlValidatingReader.Read() at
System.Xml.XmlLoader.LoadCurrentNode() at
System.Xml.XmlLoader.LoadChildren(XmlNode parent) at
System.Xml.XmlLoader.LoadElementNode() at
System.Xml.XmlLoader.LoadCurrentNode() at
System.Xml.XmlLoader.LoadCurrentNode() at
System.Xml.XmlLoader.LoadChildren(XmlNode parent) at
System.Xml.XmlLoader.LoadElementNode() at
System.Xml.XmlLoader.LoadCurrentNode() at
System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc) at
System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean
preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at
System.Xml.XmlDocument.LoadXml(String xml) at
"~~~ .NET Ed ~~~" <ti*********@abolishspam.now> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

我有一个独立的XML文件(带有相应的xml文档头)
当我使用XmlDocument加载它时工作正常。我可以毫无问题地拥有这样的孩子
元素:

< SomeChildElement type =" c" HREF =" There.aspx ID = 5英寸/>

但是一旦我将其改为这样的话:

< SomeChildElement type =" c" HREF =" There.aspx ID = 5&放大器;放大器; T = M" />

我收到一个XML异常,表明它是预期的引用(或类似的东西)。我以为& amp; amp;是一个可以随时使用的国际实体。或者它只能用作InnerText的一部分但不能用作
属性?
我该如何解决这个问题呢?

谢谢,
Emilio
Hi,
I have a standalone XML file (with the appropriate xml document header)
that works fine when I load it using XmlDocument. I can have child
elements like this without problems:

<SomeChildElement type="c" href="There.aspx?id=5" />

But as soon as I change it to something like this:

<SomeChildElement type="c" href="There.aspx?id=5&amp;t=m" />

I get an XML Exception indicating that it expected quote (or something
like that). I thought the &amp; was an internatl entity that could always
be used. Or can it only be used as part of an InnerText but not an
Attribute?
How can I resolve that problem?

Thanks,
Emilio



~~~ .NET Ed ~~~写道:
~~~ .NET Ed ~~~ wrote:
这是我得到的错误:

错误加载XML System.Xml.XmlException时:这是一个意外的令牌。预期的标记是''SEMICOLON''。
System.Xml.XmlTextReader.ExpandLiteral(XmlAttribut eTokenInfo currToken)的系统.Xml.XmlTextReader.SetLiteralValues(第14行,位于第32位)
System.Xml.XmlScanner.ScanNamedEntity()在System.Xml上的System.Xml.XmlTextReader()的System.Xml.XmlTextReader.ParseElement()中的System.Xml.XmlTextReader.SetAttributeValues()的XmlAttri buteTokenInfo fld)
System.Xml.XmlLoader.LoadCurrentNode()在System.Xml.XmlLoader.LoadChildren(XmlNode parent)中的.xmlValidatingReader.ReadNoCollectText到ken()在System.Xml.XmlValidatingReader.Read()处于System.Xml.XmlLoader.LoadCurrentNode()在
System.Xml.XmlLoader.LoadCurrentNode()处的System.Xml.XmlLoader.LoadCurrentNode()处于
系统的System.Xml.XmlLoader.LoadCurrentNode()处。
System.Xml.XmlLoader.LoadCurrentNode()的System.Xml.XmlLoader.LoadDocSequence中的Xml.XmlLoader.LoadChildren(XmlNode parent)
System.Xml.XmlLoader.LoadElementNode()
System.Xml.XmlLoader.Load(Xml)中的XmlDocument parentDoc)在System.Xml.XmlDocument.Load(XmlReader reader)的System.Xml.XmlDocument.LoadXml(String xml)上的文档doc,XmlReader reader,Boolean
preserveWhitespace

~~~ .NET Ed ~~~ < TI ********* @ abolishspam.now>在消息中写道
新闻:%2 **************** @ tk2msftngp13.phx.gbl ...
This is the error I get:

Error While loading XML System.Xml.XmlException: This is an unexpected
token. The expected token is ''SEMICOLON''. Line 14, position 32. at
System.Xml.XmlScanner.ScanNamedEntity() at
System.Xml.XmlTextReader.ExpandLiteral(XmlAttribut eTokenInfo currToken) at
System.Xml.XmlTextReader.SetLiteralValues(XmlAttri buteTokenInfo fld) at
System.Xml.XmlTextReader.SetAttributeValues() at
System.Xml.XmlTextReader.ParseElement() at System.Xml.XmlTextReader.Read()
at System.Xml.XmlValidatingReader.ReadNoCollectTextTo ken() at
System.Xml.XmlValidatingReader.Read() at
System.Xml.XmlLoader.LoadCurrentNode() at
System.Xml.XmlLoader.LoadChildren(XmlNode parent) at
System.Xml.XmlLoader.LoadElementNode() at
System.Xml.XmlLoader.LoadCurrentNode() at
System.Xml.XmlLoader.LoadCurrentNode() at
System.Xml.XmlLoader.LoadChildren(XmlNode parent) at
System.Xml.XmlLoader.LoadElementNode() at
System.Xml.XmlLoader.LoadCurrentNode() at
System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc) at
System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean
preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at
System.Xml.XmlDocument.LoadXml(String xml) at
"~~~ .NET Ed ~~~" <ti*********@abolishspam.now> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

我有一个独立的XML文件(带有相应的xml文档头)
当我使用XmlDocument加载它时工作正常。我可以毫无问题地拥有这样的孩子
元素:

< SomeChildElement type =" c" HREF =" There.aspx ID = 5英寸/>

但是一旦我将其改为这样的话:

< SomeChildElement type =" c" HREF =" There.aspx ID = 5&放大器;放大器; T = M" />

我收到一个XML异常,表明它是预期的引用(或类似的东西)。我以为& amp; amp;是一个可以随时使用的国际实体。或者它只能用作InnerText的一部分但不能用作
属性?
我该如何解决这个问题呢?

谢谢,
Emilio
Hi,
I have a standalone XML file (with the appropriate xml document header)
that works fine when I load it using XmlDocument. I can have child
elements like this without problems:

<SomeChildElement type="c" href="There.aspx?id=5" />

But as soon as I change it to something like this:

<SomeChildElement type="c" href="There.aspx?id=5&amp;t=m" />

I get an XML Exception indicating that it expected quote (or something
like that). I thought the &amp; was an internatl entity that could always
be used. Or can it only be used as part of an InnerText but not an
Attribute?
How can I resolve that problem?

Thanks,
Emilio



使用十六进制%26代替。


Use hexadecimal %26 instead.


~~~ .NET Ed ~~~写道:
~~~ .NET Ed ~~~ wrote:
我有一个独立的XML文件(带有相应的xml文档头)
当我使用XmlDocument加载它时工作正常。我可以毫无问题地拥有这样的子元素:

< SomeChildElement type =" c" HREF =" There.aspx ID = 5英寸/>

但是一旦我将其改为这样的话:

< SomeChildElement type =" c" HREF =" There.aspx ID = 5&放大器;放大器; T = M" />

我得到一个XML异常,表明它有预期的引用(或类似
)。我以为& amp; amp;是一个可以随时使用的国际实体。或者它只能用作InnerText的一部分但不能用作属性?
如何解决这个问题?
I have a standalone XML file (with the appropriate xml document header)
that works fine when I load it using XmlDocument. I can have child elements
like this without problems:

<SomeChildElement type="c" href="There.aspx?id=5" />

But as soon as I change it to something like this:

<SomeChildElement type="c" href="There.aspx?id=5&amp;t=m" />

I get an XML Exception indicating that it expected quote (or something like
that). I thought the &amp; was an internatl entity that could always be
used. Or can it only be used as part of an InnerText but not an Attribute?
How can I resolve that problem?




这很奇怪。我无法重现这个问题。什么是第14行,

位置32?无论如何提供更多信息。


-

Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com


这篇关于不能使用&amp; amp;作为属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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