2

Based on the question I have ask earlier: How can you save the constant update and the finally save the output as a file with XMLModifier

The previous question I have done is do all the update and finally output it into a XML by xm.ouput("output.xml");

I know you have mention that:

One operation per offset value: two repeating operations at the same offset will cause exception

Example, I probably a list of path I would like to edit, but I have forgotten there would be duplicate. I wouldnt know until there is error and a exception is produce.

VTDGen vg = new VTDGen();
vg.parseFile("input.xml", false);
vn.getNav();
AutoPilot ap = new AutoPilot(vn);
XMLModifier xm = new XMLModifier(vn);

public void updateToken(String path, String value) 
{
    ap.selectPath(path);
    .........
    xm.updateToken(i,value);
}

public static void main(String args[])
{
   updateToken("/a/b/c", "hello");
   //updateToken("/a/b", "world");(*ignore)
   updateToken("/a/b/c", "john");
}

But is there a way 2nd update possible to? By overwriting, or there is a method to check that that point is being updated? Any suggestions?


I have a XML file something like this.

<a>
   <b>
      <c>value1</c>
   </b>
   <b>
      <c>value2</c>
   </b>
</a>

I decided to use the first updateToken("/a/b/c", "hello") to update only the 2nd C node - value2 -> hello And the next updateToken("/a/b/c", "john") to update both of the C node. The output I gotten was:

<a>
   <b>
      <c>john</c>
   </b>
   <b>
      <c>hello</c>
   </b>
</a>

And later produces an exception, which I know there is two operation happening on the same offset. So I am wondering, is it possible to not even do the 2nd updateToken() since there has been one update on that offset

Like do a search for update marking before starting to mark, if not, there will be some update here and there...

Community
  • 1
  • 1
jilldc13
  • 33
  • 1
  • 5
  • by 2nd update are you referring to (/a/b, "world") or (/a/b/c, "john"), which one are you referring to? – vtd-xml-author Feb 17 '16 at 07:10
  • @vtd-xml-author hmm, I am referring to `("a/b/c", "john");` Let me rephrase a bit, so the duplicated update will be from at `updateToken("/a/b/c", "hello")`, follow by a second repeated update `updateToken("/a/b/c", "john");` – jilldc13 Feb 17 '16 at 07:16

1 Answers1

0

UpdateToken should throw a ModifyException in case there is more than one operation at an offset value. Furthermore, the later updates will not be registered with XMLModifier, nor pushed thru to the output. Overall, please consider catching the modifyException and handle it in your code to account for the operation overlaps.

vtd-xml-author
  • 3,319
  • 4
  • 22
  • 30