|
|
|
Re: problem having namespace declaration within xml tree [message #901269 is a reply to message #901196] |
Fri, 10 August 2012 14:50 |
Konstantin Komissarchik Messages: 1077 Registered: July 2009 |
Senior Member |
|
|
The prefix that is specified in @XmlNamespace is there largely to facilitate namespace resolution within various XML binding annotations. Once you've linked the two, Sapphire will be able to read and update your XML documents regardless of the style of namespace declaration.
Here is roughly how this works...
1. Resolve namespace of element names in binding annotations.
2. When reading, only match based on namespace URI.
3. When creating a new element, look for an existing namespace declaration in element hierarchy. If found, use the namespace as declared (no prefix or prefix as specified in the document).
4. If an existing namespace declaration is not found, Sapphire needs to establish one. Here, there are many legal options, all leading to semantically equivalent documents. To avoid complicating the XML binding annotations, Sapphire implements one of the common options. The namespace declaration is written in the root element using the namespace prefix as specified in @XmlNamespace. If prefix "p" is already in use, Sapphire will look for an available one using "p1", "p2", "p3", etc. system. Declaring namespace at the root of the document is commonly preferred over local declarations as it results in fewer namespace declarations.
Once you get this to work, if you are still unhappy with the behavior in #4, Sapphire provides a way to write a custom binding for particular property. For instance, see @CustomXmlElementBinding and ElementBindingImpl. Of course, I would recommend that you double-check whether achieving a particular behavior when establishing a namespace is worth the extra cost to implement and test a custom binding.
Hope this helps.
- Konstantin
|
|
|
|
|
Re: problem having namespace declaration within xml tree [message #937211 is a reply to message #937047] |
Mon, 08 October 2012 19:44 |
Eyck Jentzsch Messages: 21 Registered: August 2012 |
Junior Member |
|
|
Hi Konstantin,
THX for the offer, here are the respective classes:
@GenerateImpl
public interface IEquation {
ModelElementType TYPE = new ModelElementType( IEquation.class );
@Type( base = IMath.class )
@XmlBinding( path = "math" )
@Label( standard = "math" )
@Required
ImpliedElementProperty PROP_MATH = new ImpliedElementProperty( TYPE, "math" );
IMath getMath();
@Type( base = IParameter.class )
@XmlListBinding(path="listOfParameters", mappings = { @XmlListBinding.Mapping( element = "reactant", type = IParameter.class ) } )
@Label( standard = "listOfParameters" )
ListProperty PROP_LISTOFPARAMETERS = new ListProperty( TYPE, "listOfParameters" );
ModelElementList<IParameter> getListOfParameters();
}
@GenerateImpl
public interface IMathBase extends IModelElement {
ModelElementType TYPE = new ModelElementType( IMathBase.class );
@XmlBinding( path = "@class" )
@Label( standard = "class" )
ValueProperty PROP_CLAZZ = new ValueProperty( TYPE, "clazz" );
Value<String> getClazz();
void setClazz( String value );
@XmlBinding( path = "@style" )
@Label( standard = "style" )
ValueProperty PROP_STYLE = new ValueProperty( TYPE, "style" );
Value<String> getStyle();
void setStyle( String value );
@XmlBinding( path = "@id" )
@Label( standard = "id" )
ValueProperty PROP_ID = new ValueProperty( TYPE, "id" );
Value<String> getId();
void setId( String value );
}
@GenerateImpl
@XmlNamespace(uri = "http : //www.w3.org/1998/Math/MathML" )
@Label(standard="Math")
public interface IMath extends IMathBase {
ModelElementType TYPE = new ModelElementType( IMath.class );
@Type( base = IOperand.class, possible = { IApply.class, ICi.class, ICn.class })
@XmlElementBinding(
path="",
mappings = {
@XmlElementBinding.Mapping( element = "apply", type = IApply.class ),
@XmlElementBinding.Mapping( element = "ci", type = ICi.class ),
@XmlElementBinding.Mapping( element = "cn", type = ICn.class )
} )
ElementProperty PROP_OPERAND = new ElementProperty(TYPE, "operand");
ModelElementHandle<IOperand> getOperand();
}
- Eyck
PS: I had to modify the namespace uri as I'm currently not allowed to post links....
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.39662 seconds