Forum Discussion
SmartBear_Suppo
14 years agoSmartBear Alumni (Retired)
Hi!
this requires a little more advanced scripting that uses the XmlBeans SchemaTypeSystem built internally in soapUI. First you need to create an XmlObjectTreeModel for your request message:
// create an XmlObjectTreeModel
def model = new com.eviware.soapui.support.editor.views.xml.outline.support.XmlObjectTreeModel(
mockRequest.mockOperation.operation.getInterface().definitionContext.schemaTypeSystem,
org.apache.xmlbeans.XmlObject.Factory.parse( mockRequest.requestContent) );
To determine if an element is optional you will need to get the type information for its parent element which can give you information on the elements it contains based on its contentModel (this is XmlBeans-speak)
// select parent of desired node so we can get its contentModel
def nodes = model.selectTreeNodes( "//id[1]/.." );
def schemaType = nodes[0].schemaType;
Now we need to query the type for this information, for example to get the minOccurs of the first child particle in a sequence (which will be 0 if it is optional), we could use
// get particle for first child in this sequence and show if it is optional
def childParticle = schemaType.contentModel.particleChildren[0]
log.info schemaType.contentModel.particleChildren[0].minOccurs
Hope this helps you getting started, dig in to the XmlBeans SchemaType APIs at http://xmlbeans.apache.org/docs/2.4.0/r ... aType.html to find out how you can traverse the type information model, etc..
regards!
/Ole
eviware.com
this requires a little more advanced scripting that uses the XmlBeans SchemaTypeSystem built internally in soapUI. First you need to create an XmlObjectTreeModel for your request message:
// create an XmlObjectTreeModel
def model = new com.eviware.soapui.support.editor.views.xml.outline.support.XmlObjectTreeModel(
mockRequest.mockOperation.operation.getInterface().definitionContext.schemaTypeSystem,
org.apache.xmlbeans.XmlObject.Factory.parse( mockRequest.requestContent) );
To determine if an element is optional you will need to get the type information for its parent element which can give you information on the elements it contains based on its contentModel (this is XmlBeans-speak)
// select parent of desired node so we can get its contentModel
def nodes = model.selectTreeNodes( "//id[1]/.." );
def schemaType = nodes[0].schemaType;
Now we need to query the type for this information, for example to get the minOccurs of the first child particle in a sequence (which will be 0 if it is optional), we could use
// get particle for first child in this sequence and show if it is optional
def childParticle = schemaType.contentModel.particleChildren[0]
log.info schemaType.contentModel.particleChildren[0].minOccurs
Hope this helps you getting started, dig in to the XmlBeans SchemaType APIs at http://xmlbeans.apache.org/docs/2.4.0/r ... aType.html to find out how you can traverse the type information model, etc..
regards!
/Ole
eviware.com
Related Content
- 3 months ago
- 2 years ago
- 7 years ago
- 11 years ago
Recent Discussions
- 45 minutes ago
- 3 hours ago