Remove the remaining new line after using VTD-XML to remove an element

纵然是瞬间 提交于 2020-02-25 04:42:07

问题


I'm trying to remove a set of child elements from a parent element using 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.

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);

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

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().

Questions

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?

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

Thanks for your help.

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.


回答1:


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...



来源:https://stackoverflow.com/questions/17441393/remove-the-remaining-new-line-after-using-vtd-xml-to-remove-an-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!