使用VTD-XML删除元素后,删除剩余的新行 [英] Remove the remaining new line after using VTD-XML to remove an element

查看:107
本文介绍了使用VTD-XML删除元素后,删除剩余的新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用VTD-XML从父元素中删除一组子元素.

I'm trying to remove a set of child elements from a parent element using VTD-XML.

不幸的是,在删除元素之后,它留下了被删除元素先前占用的新行. VTD-XML作者

Unfortunately after removing an element, it leaves behind the new line that the removed element previously occupied. This behaviour is also observed by a reader of an article on VTD-XML by the VTD-XML author here. I'm trying to work out how to remove this new line.

我设法通过操纵存储在底层64位VTD令牌中的长度值来覆盖换行符(附加2个字节),取得了一定的成功.代码段如下:

I managed to achieve a modicum of success by manipulating the length value stored in the underlying 64-bit VTD token to cover the new line character (additional 2 bytes). Code snippet is as follows:

// XMLModifier modifier
modifier.remove(vn.getElementFragment()+0x200000000L);

我已经测试过,它可以在VTD-XML示例的ex_16中提供的old_cd.xml上很好地工作.

I've tested that this works well on the old_cd.xml provided in ex_16 of the VTD-XML Examples.

但是,当我在工作文件上尝试相同的方法时,尝试调用modifier.output()时会引发ModifyException错误,特别是modifier.check2()会引发该错误.

However when I try this same approach on my working file, a ModifyException error is thrown when I attempt to call modifier.output(), specifically it is thrown by modifier.check2().

问题

<罢工> 1.为什么上述方法会导致check2()失败?我不认为我在VTD令牌上溢出了位,文件是<. 2MB.参见更新.
2.是否有更好的方法来删除剩余的新行?

1. Why would the above approach cause check2() to fail? I don't think I'm overflowing the bits on the VTD token, file is < 2MB. See Update.
2. Is there a better approach to remove the remaining new line?

我对VTD-XML还是很陌生,所以我将不胜感激任何建议和见解,并向经验丰富的用户学习.

I'm still fairly new to VTD-XML so I would greatly appreciate any advice and insight and learn from more experienced users.

感谢您的帮助.

更新
哇,在编写这个问题的过程中,我意识到我忘了考虑不同的字符编码,并将调整后的long值更新为1个字节解决了check2()问题! (这是花时间暂停并重新考虑/解决问题的另一个原因).

Update
Wow, in the process of writing this question I realise that I forgot to consider the different character encodings and updating the adjusting long value to 1 byte fixed the check2() problem! (another reason to take the time to pause and rethink/write out the problem).

我仍然想从经验丰富的用户那里了解是否有更好的方法.

I'd still like to know from more experienced users if there are better approaches to this.

推荐答案

要回答您的问题,我认为这需要在API级别完成,并且需要注意一些额外的细节,例如删除所有内容的选项周围的空白或没有空白.它需要在下一个版本中完成...

To answer your question, I think this needs to be done at the API level and it needs to take care a few extra details, like the options to remove all surrounding white spaces or none of the white spaces. It needs to be done in the next release...

这篇关于使用VTD-XML删除元素后,删除剩余的新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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