Hi Vlad

 

I’m sorry. I looked into it a bit more and I take back the comment about substitute() removing the descendants. I thought substitute() was internally like a “removeOldElement() + addNewElement()” but on looking at it a bit more it’s clear it’s more like “changeName() + changeType”. This in turn means there’s a scenario (into which you may fall) in which substitute() really is not what should be recommended to solve your problem – but if you can forward a repro scenario with the schema and the test code I’ll take a look and see.

 

Cheers,

 

Lawrence

 


From: Lawrence Jones
Sent: Monday, February 06, 2006 11:06 AM
To: '[email protected]'; '[EMAIL PROTECTED]'
Subject: RE: Need help with substitutionGroup

 

Hi Vlad

 

I wouldn’t use changeName() unless you know exactly what you are doing. The XmlCursor methods are more for manipulating XML where there is no schema. substitute() is the right thing for this and should work. If it’s not working then we should file a bug. But I think we should be certain first.

 

First of all I’m still not entirely sure what you want to do. The structure you put forward is nested. There are multiple <Apply>’s within other <Apply>’s. Now this is fine – but be aware that if you substitute() something in the middle of the tree then all its descendants will “disappear” – you could copy them in by keeping a “pointer” to the old one and then copying recursively down the tree (provided the definition of <AttributeValue> allows that sort of structure) but just so you know.

 

Secondly you need to make sure that you are able to substitute one for the other according to the rules of schema. In your case it looks as though the thing you are trying to substitute one of the <_expression_> elements in the sequence within the definition of <ApplyType>. <AttributeValue> is declared as substitutable for <_expression_> - so this should be OK.

 

Given all this, to me it looks like navigating to the <Apply> you are interested in and then the following call:

 

yourApplyElement.substitute(new QName(“your_namespace”, “AttributeValue”), AttributeValue.type);

 

should give you a new “blank” AttributeValue object in the right place which you could then “fill in”. If it does not what goes wrong? Again I’m not quite following which of the <Apply> objects you are attempting to substitute(), exactly what code you are calling to do so, what you see as a result and what the difference is from what you were expecting to see?

 

Can you attach your full schema (or a smaller test one if your full one is too large) and the test code you’re running and I’ll take a look.

 

Cheers,

 

Lawrence

 


From: Vlad Mangeym [mailto:[EMAIL PROTECTED]
Sent: Monday, February 06, 2006 10:31 AM
To: [email protected]
Subject: RE: Need help with substitutionGroup

 

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!

Reply via email to