Lawrence,

Thank you for your reply.
Sorry for the confusion, I have posted wrong part of the schema.
The correct part for the AttributeValue:

    <xs:element name="AttributeValue" type="xacml:AttributeValueType" substitutionGroup="xacml:_expression_"/>
    <xs:complexType name="AttributeValueType" mixed="true">
        <xs:complexContent mixed="true">
            <xs:extension base="xacml:ExpressionType">
                <xs:sequence>
                    <xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
                </xs:sequence>
      &n bsp;         <xs:attribute name="DataType" type="xs:anyURI" use="required"/>
                <xs:anyAttribute namespace="##any" processContents="lax"/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>


Also, I have found FAQ about substitution grouop and, as I understand, there are two ways to do it:

1. Using substitute

This did not work for me. The scenario that I have is such that I need to replace an Element of the Apply which is an Apply itself by the Element which is an AttributeValue.

I have:


            <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-to-double">
                <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-subtract">
                    <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only">
                        <SubjectAttributeDesignator
                              AttributeId="urn:oasis:names:tc:xacml:2.0:conformance-test:age"
                              DataType="http://www.w3.org/2001/XMLSchema#integer"/>
                    </Apply>
                   <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only">
                        <EnvironmentAttributeDesignator
                              AttributeId="urn:oasis:names:tc:xacml:2.0:conformance-test:bart-simpson-age"
                              DataType="http://www.w3.org/2001/XMLSchema#integer"/>
                    </Apply>
                </Apply>
            </Apply>
            <AttributeValue
                  DataType="http://www.w3.org/2001/XMLSchema#double">5.0</AttributeValue>


When I replace first Apply with AttributeValue I get:
            <Apply DataType="http://www.w3.org/2001/XMLSchema#double">6.0     </Apply>
            <AttributeValue
                  DataType="http://www.w3.org/2001/XMLSchema#double">5.0</AttributeValue>


After I call substitute on it I get:
            <_expression_ DataType="http://www.w3.org/2001/XMLSchema#double" type="AttributeValue" >6.0     </_expression_ >
            <AttributeValue
                  DataType="http://www.w3.org/2001/XMLSchema#double">5.0</AttributeValue>


2. Using cursor and setName() (FAQ says changeName, but ther e is no function with this name anymore).

This almost works for me. After calling setName I get:

            <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#double" type="Apply" >6.0     </AttributeValue>
            <AttributeValue
                  DataType="http://www.w3.org/2001/XMLSchema#double">5.0</AttributeValue>

So my only issue now is how to make it not to put type="Apply"?

Thanks,
Vlad

Lawrence Jones <[EMAIL PROTECTED]> wrote:
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 mentione d 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:Expressio n" 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!


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