逃脱序列不起作用? [英] Escapes Sequences Not Working?

查看:65
本文介绍了逃脱序列不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您检查下面的完整XML,您将看到一个元素Notes

包含...


< Notes>测试替换测试[LINE]& amp; [LINE]替换< / Notes>


正如你所看到的,我已经正确地(我认为)用&&& >
"& amp;"。如果我将此XML放在一个文件中并使用Internet Explorer打开它

正确处理&符号。在我的Java servlet中,我使用SAX

解析器来解析XML并将其写入数据库。当该解析器获得注释时的
返回的元素是转义序列中的&符号(不包括

包括)中的符号。之后的一切都是

截断。我发现任何转义序列都会发生这种情况

(因为它们都以&符号开头)。


我没有错误并且记录被写入到数据库,只需要一个

截断的Notes字段。


任何想法我能找到什么?


<?xml version =" 1.0"?>

< MBO>

<记录>

< ID> ; -49781293< / ID>

< OrderDate> 2004-08-24 15:19:31< / OrderDate>

< MemoBillType> 5< / MemoBillType>

< AccountNum> 1< / AccountNum>

< BillToAddress> TEST< / BillToAddress>

< ShipToAddress>与Bill To相同地址< / ShipToAddress>

< RegMgr> John Doe< / RegMgr>

< SecCode> 308040-860602< / SecCode>

< Notes>测试替换测试[LINE]& amp; [LINE]替换< / Notes>

< RequireDate> TEST< / RequireDate>

< R ackInfo> TEST< / RackInfo>

< CallPhoneNumber> TEST TEST< / CallPhoneNumber>

< SubRecord_A>

< LineNum> 1< ; / LineNum>

<数量> 1< /数量>

< PartNum> TEST< / PartNum>

< ShipDesignation> TEST< / ShipDesignation>

< Price> NULL_VALUE< / Price>

< Discount> NULL_VALUE< / Discount>

< Notes> ; TEST TEST TEST< / Notes>

< / SubRecord_A>

< / Record>

< / MBO>

If you examine the complete XML below you will see an element "Notes"
consisting of...

<Notes>test replace test[LINE]&amp;[LINE]replace</Notes>

As you can see I have properly (I think) escaped the ampersand (&) with
"&amp;". If I place this XML in a file and open it with Internet Explorer
the ampersand is properly dealt with. In my Java servlet I am using a SAX
parser to parse the XML and write it to a database. When that parser gets
to the "Notes" element all that is returned is the characters up to (not
including) the ampersand in the escape sequence. Everything after that is
truncated. I have found that this will happen with any escape sequence
(since they all start with the ampersand).

I get no errors and the record is written to the database, just with a
truncated Notes field.

Any ideas what I can look for?

<?xml version="1.0"?>
<MBO>
<Record>
<ID>-49781293</ID>
<OrderDate>2004-08-24 15:19:31</OrderDate>
<MemoBillType>5</MemoBillType>
<AccountNum>1</AccountNum>
<BillToAddress>TEST</BillToAddress>
<ShipToAddress>Same as Bill To Address</ShipToAddress>
<RegMgr>John Doe</RegMgr>
<SecCode>308040-860602</SecCode>
<Notes>test replace test[LINE]&amp;[LINE]replace</Notes>
<RequireDate>TEST</RequireDate>
<RackInfo>TEST</RackInfo>
<CallPhoneNumber>TEST TEST</CallPhoneNumber>
<SubRecord_A>
<LineNum>1</LineNum>
<Quantity>1</Quantity>
<PartNum>TEST</PartNum>
<ShipDesignation>TEST</ShipDesignation>
<Price>NULL_VALUE</Price>
<Discount>NULL_VALUE</Discount>
<Notes>TEST TEST TEST</Notes>
</SubRecord_A>
</Record>
</MBO>

推荐答案




Rick Brandt写道:


Rick Brandt wrote:
如果你检查一下在下面的完整XML中,您将看到一个元素Notes
由...组成

< Notes>测试替换测试[LINE]& amp; [LINE]替换< / Notes> ;

正如你所看到的,我已经正确地(我认为)通过
& a逃脱了&符号(&)熔点;" ;.如果我将此XML放在一个文件中并使用Internet Explorer打开它
正确处理&符号。在我的Java servlet中,我使用SAX
解析器来解析XML并将其写入数据库。当该解析器获得Notes时返回的元素是转义序列中的&符号(不包括
包括)中的符号。之后的一切都被截断了。我发现任何转义序列都会发生这种情况
(因为它们都以&符号开头)。
If you examine the complete XML below you will see an element "Notes"
consisting of...

<Notes>test replace test[LINE]&amp;[LINE]replace</Notes>

As you can see I have properly (I think) escaped the ampersand (&) with
"&amp;". If I place this XML in a file and open it with Internet Explorer
the ampersand is properly dealt with. In my Java servlet I am using a SAX
parser to parse the XML and write it to a database. When that parser gets
to the "Notes" element all that is returned is the characters up to (not
including) the ampersand in the escape sequence. Everything after that is
truncated. I have found that this will happen with any escape sequence
(since they all start with the ampersand).




你的SAX代码看起来如何?您可能会获得几个字符块

数据作为< Notes>的内容。元素。


-


Martin Honnen
http://JavaScript.FAQTs.com/


" Martin Honnen" <毫安******* @ yahoo.de>在留言中写道

news:41 *********************** @ newsread2.arcor-online.net ...
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:41***********************@newsread2.arcor-online.net...
您的SAX代码如何?您可能会获得几个字符数据块作为< Notes>的内容。元素。
How does your SAX code look? You might get several chunks of character
data as the content of the <Notes> element.




public void characters(char [] ch,int start,int length)

抛出SAXException,DataSetException {

尝试{

if(elementStart){

elementStart = false;

String s = new String(ch,start,length );


我正在使用JBuilder 7,它有一个内置的SAX解析器对象模板,

扩展了DefaultHandler。问题似乎是上面最后一行的长度参数

。如果我在调试模式下检查ch []数组,它仍然是

包含来自Notes的所有文本。元素,但从解析器传递的长度参数是

(由于某种原因)设置为&符号的第一个

,而不是扩展到元素关闭标记。

因此我用于插入数据库的String被截断。

-

我没有查看电子邮件帐户附上

到此消息。发送给... ...

在Hunter dot com的RBrandt



public void characters(char[] ch, int start, int length)
throws SAXException, DataSetException {
try {
if (elementStart) {
elementStart = false;
String s = new String(ch, start, length);

I''m using JBuilder 7 and it has a built in SAX parser object template that
extends DefaultHandler. The problem seems to be with the length argument
on the last line above. If I examine the ch[] array in debug mode it still
has all of the text from the "Notes" element, but the length argument being
passed from the parser is (for some reason) being set to the first
occurrence of an ampersand instead of extending to the element close tag.
So the String s that I use for insertion to the database is truncated.
--
I don''t check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com



在文章< 2p *** *********@uni-berlin.de> ;,

Rick Brandt< ri ********* @ hotmail.com>写道:
In article <2p************@uni-berlin.de>,
Rick Brandt <ri*********@hotmail.com> wrote:
我正在使用JBuilder 7,它有一个内置的SAX解析器对象模板,它扩展了DefaultHandler。问题似乎与上面最后一行的长度参数
有关。如果我在调试模式下检查ch []数组,它仍然具有来自Notes的所有文本。元素,但是从解析器传递的长度参数(由于某种原因)被设置为&符号的第一个出现而不是扩展到元素关闭标记。
所以字符串用于插入数据库的s被截断。
I''m using JBuilder 7 and it has a built in SAX parser object template that
extends DefaultHandler. The problem seems to be with the length argument
on the last line above. If I examine the ch[] array in debug mode it still
has all of the text from the "Notes" element, but the length argument being
passed from the parser is (for some reason) being set to the first
occurrence of an ampersand instead of extending to the element close tag.
So the String s that I use for insertion to the database is truncated.




你不能用字符串的其余部分调用字符()吗? />
我不能保证你会立刻得到它。


- Richard



And you don''t get more calls to characters() with the rest of the string?
There''s no guarantee you will get it all at once.

-- Richard


这篇关于逃脱序列不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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