1

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.

4

1 回答 1

0

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

于 2013-07-18T19:11:25.187 回答