|
From: W K <wka...@ho...> - 2014-05-27 21:22:00
|
I have the following xml snippet:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<notes version="1.0">
<note-count>5</note-count>
<refs>
<b id="1">
<c id="1">
<v id="2">
<note-id>1</note-id>
<note-id>2</note-id>
<note-id>5</note-id>
</v>
</c>
<c id="4">
<v id="2">
<note-id>1</note-id>
<note-id>2</note-id>
<note-id>3</note-id>
</v>
</c>
</b>
<b id="22">
<c id="1">
<v id="2">
<note-id>1</note-id>
<note-id>4</note-id>
<note-id>5</note-id>
</v>
</c>
</b>
</refs>
<notes>
I need to remove all elements: <note-id>1</note-id>
I have the following code snippet to remove all of the elements:
XM.bind(VN);
AutoPilot ap = new AutoPilot( VN );
// find all note-id elements with a value of '1'
String xpath = "//note-id[text()='1']";
ap.selectXPath( xpath );
int i = -1;
while ( ( i = ap.evalXPath() ) != -1 ) {
log.debug( "element/value: " + VN.toNormalizedString( VN.getCurrentIndex() ) + "/" + VN.toNormalizedString( VN.getText() ));
XM.remove();
}// while
If I just print out the xpath results, the element names and values are correct. However, when trying to remove each value, I get the following error:
java.lang.ArrayIndexOutOfBoundsException: -1
at com.ximpleware.FastLongBuffer.longAt(FastLongBuffer.java:309)
at com.ximpleware.VTDNav.getTokenDepth(VTDNav.java:1327)
at com.ximpleware.VTDNav.getElementFragment(VTDNav.java:1079)
at com.ximpleware.XMLModifier.remove(XMLModifier.java:210)
at com.razorphish.android.util.XmlUtil.deleteNoteIds(BibleNotesXmlUtil.java:633)
at com.razorphish.android.test.XmlUtilTest.deleteNoteById(BibleNotesXmlUtilTest.java:146)
at com.razorphish.android.test.XmlUtilTest.test(BibleNotesXmlUtilTest.java:49)
What is the best practice for removing these elements in bulk?
Thanks for any help you can provide.
|