set limit to number of children in an element in xml

I have an XML file as follows

<abc>
  <property>
    <Recentlyopenedfiles>
    <File Path="c:\hai.txt" />
    <File Path="C:\old.java" />
    </Recentlyopenedfiles>
   </property>
</abc>

I am using jdom2 SAXBuilder to parse the xml in java.I need to save all recently opened files in <Recentlyopenedfiles>. At the maximum this has to hold only three paths(i.e) 3 recently opened files path.

So,I need to know

  1. Are there any mechanism to set limit to child nodes?
  2. How to index child and perform stack operation so that last opened file saved in first file path.

Thanks.

Jon Skeet
people
quotationmark

There are declarations in XSD to limit the number of child elements, but I don't think that's relevant in your particular case. When it comes to parsing and then modifying the XML, you'll just need to perform the limiting by hand.

In terms of "stacking" - if you just always add items to the start of the element rather than at the end (using parent.addContent(0, newChild)) , you'll end up with the last one you add being the first in the document. You can then count how many you've got, and remove any extra ones.

people

See more on this question at Stackoverflow