You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Ajay Aggarwal <aa...@covergence.com> on 2007/06/11 21:37:11 UTC

caching XmlObjects for a changing XML document

I am reading an XML schema file as an XML document and modifying it per
my project needs. Modification happens in several places and in most
places modification is of the nature: remove SchemaProperty 'prop' from
SchemaType 'type'.

 

So the flow of my program is roughly:

 

main() 

{

     XmlObject doc = XmlObject.Factory.parse(inputSchemaFile)

     SchemaTypeSystem sts = XmlBeans.compileXsd(doc, ...)

     

     Now I begin processing sts and call 

         removeProperty (doc, schemaType,  schemaProperty) 

     in several places

     

     When done, save doc as new schema file.

}

 

removeProperty (XmlObject doc, SchemaType type, SchemaProperty prop) 

{

    XmlObject xoType = doc.selectPath (xpath for type)

    XmlObejct xoProp = xoType.selectPath (xpath for prop)

    Node domNode = xoProp.getDomNode()

    domNode.getParentNode().removeChild(domNode)

}

 

I am finding that selectPath seems to be very expensive. So I wanted to
cache the XmlObjects for types, such that in future if xpath is same, I
can return from my local cache instead of calling selectPath.

 

My question is in this dynamic situation where I am changing the
underlying XML instance (via removeProperty call above), will caching
XmlObject(s) work?