Hi Vlad

 

I’m a little confused over exactly what you’re trying to do. Substitution groups define elements which can replace other elements – therefore I’m not sure what AttributeValue does in your example below and nor is it mentioned in the bits of schema you have.

 

Nonetheless the way you do substitution in XmlBeans is to use the substitute() method (which is available on every generated XmlBean) e.g. suppose you have an outerObject with a child element called “substitutingThis”. You would then add a new “substitutingThis” using addNewSubstitutingThis() as usual:

 

        SubstitutingThis substitutingThis  = outerObject.addNewSubstitutingThis();

 

Once you have a reference to the thing you want to substitute then you would substitute it as follows:

 

        QName qName = new QName(

            "namespace_of_element_you_are_using_as_substitution", " local_name_of_element_you_are_using_as_substitution ");

 

        SubstType resultObject = (SubstType) substitutingThis.substitute(qName, SubstType.type);

 

where SubstType is whatever type the element you are substituting with has.

 

Then resultObject will have type SubstType and you can then use the setXXX() methods on it exactly as you do normal child elements.

 

Hope that helps.

 

Cheers,

 

Lawrence

 


From: Vlad Mangeym [mailto:[EMAIL PROTECTED]
Sent: Saturday, February 04, 2006 5:53 PM
To: [email protected]
Subject: Need help with substitutionGroup

 

I have the following types:

(Element I am trying to update):

    <xs:element name="Apply" type="xacml:ApplyType" substitutionGroup="xacml:_expression_"/>
    <xs:complexType name="ApplyType">
        <xs:complexContent>
            <xs:extension base="xacml:ExpressionType">
                <xs:sequence>
                    <xs:element ref="xacml:_expression_" minOccurs="0" maxOccurs="unbounded"/>
                </xs:sequence>
                <xs:attribute name="FunctionId" type="xs:anyURI" use="required"/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>


(Element I want to add to it):

    <xs:element name="Apply" type="xacml:ApplyType" substitutionGroup="xacml:_expression_"/>
    <xs:complexType name="ApplyType">
        <xs:complexContent>
            <xs:extension base="xacml:ExpressionType">
                <xs:sequence>
                    <xs:element ref="xacml:_expression_" minOccurs="0" maxOccurs="unbounded"/>
                </xs:sequence>
                <xs:attribute name="FunctionId" type="xs:anyURI" use="required"/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>


I am trying this Java code, but the element still stays as _expression_ (not AttributeValue):
            
            //I already have applyXml loaded
      
            ExpressionType exp = null;
            AttributeValueDocument exprDoc = AttributeValueDocument.Factory
                    .newInstance();
            AttributeValueType value = exprDoc.addNewAttributeValue();
            value.setDataType(dataType);
            ((SimpleValue) value).setStringValue("test");
            exp = value;
          
           applyXml.addNewExpression(0);
           applyXml.getExpressionArray()[0].set(exp);


Pleas help!


Relax. Yahoo! Mail virus scanning helps detect nasty viruses!

Reply via email to