|
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, From: Lawrence Jones 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, From: Vlad Mangeym
[mailto:[EMAIL PROTECTED]
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, From: Vlad Mangeym
[mailto:[EMAIL PROTECTED] I have the following types: Relax. Yahoo! Mail virus
scanning helps detect nasty viruses! Relax. Yahoo! Mail virus
scanning helps detect nasty viruses! |
- Need help with substitutionGroup Vlad Mangeym
- RE: Need help with substitutionGroup Lawrence Jones
- RE: Need help with substitutionGroup Vlad Mangeym
- RE: Need help with substitutionGroup Lawrence Jones
- RE: Need help with substitutionGroup Lawrence Jones
- RE: Need help with substitutionGroup Vlad Mangeym
- RE: Need help with substitutionGroup Lawrence Jones

