Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] MOXy: Mapping to a Text Node in a Subelement

Hello,

In case anyone is interested, I figured out what the problem was.

It turns that the problems in resolving the XPaths were caused by the
namespace prefix errors.  

It appears that EclipseLink requires every included or imported namespace to
be defined in the schema statement.  We use lots of included namespaces, and
EclipseLink's parser does not resolve these.  The statements are like:

<xsd:import namespace="http://foo.org/bar/9/baz/1.1";
schemaLocation="../bar/baz.xsd"/>

I tried swapping out XercesImpl.jar from v2.9.0 to v2.9.1, but it didn't
make any difference.  

Here's what I ended up doing:

1.  I looked up the imported namespace prefixes myself.
2.  Typed them into the WorkBench and set the "Declare" value to false.  
3.  Even the "target namespace" requires a prefix for some reason, so I
typed in "ns1" and set "Declare" to false.

This got rid of the namespace errors, and when I went back to re-map
Address, I found that the Schema Context dialog window no longer had
multiple duplicate entries for Address.  I saw the multiple duplicate
entries before and didn't realize it was a problem.  So now I am able to
select the one element entry for Address and map its subelements properly. 
Hurray!

So it seems like the problem with parsing included namespace prefixes is a
bug.  Is it ok if I log the bug?

Thanks,
Polly



amphoras wrote:
> 
> Hi,
> 
> I have successfully followed Oracle's TopLink 
> http://www.oracle.com/technology/products/ias/toplink/technical/tips/ox/index.htm
> tutorial   for XML data binding, but now that I'm trying to create a
> mapping with my own schema, I'm running into some puzzling errors.  I have
> Googled all over the web and in these forums to no avail.  MOXy looks like
> a really cool and powerful tool that does exactly what I want, so I'd
> really like to be able to use it.  Hopefully someone can help me. 
> 
> What I'm trying to do is map to a text node in a subelement.  I have read
> the documentation 
> http://wiki.eclipse.org/Introduction_to_XML_Mappings_%28ELUG%29#Mapping_to_a_Text_Node_in_a_Subelement
> Mapping to a Text Node in a Subelement  .  So it looks like MOXy supports
> this, and I'm not sure why it's not working.  I am using the WorkBench
> instead of coding the mappings with Java though, if that makes any
> difference.
> 
> Here's what I have.  This is my Components.xsd file:
> 
> 	<xsd:complexType name="AddressBaseType" abstract="true">
> 		<xsd:sequence>
> 			<xsd:element ref="AttentionOfName" minOccurs="0"
> maxOccurs="unbounded"/>
> 			<xsd:element ref="CareOfName" minOccurs="0" maxOccurs="unbounded"/>
> 			<xsd:choice>
> 				<xsd:element ref="AddressLine" minOccurs="0" maxOccurs="unbounded"/>
> 				<xsd:sequence>
> 					<xsd:element ref="LineOne" minOccurs="0"/>
> 					<xsd:element ref="LineTwo" minOccurs="0"/>
> 					...
> 				</xsd:sequence>
> 				<xsd:sequence>
> 					...
> 				</xsd:sequence>
> 			</xsd:choice>
> 			<xsd:element ref="CityName" minOccurs="0"/>
> 			<xsd:element ref="StateCode" minOccurs="0" maxOccurs="unbounded"/>
> 			<xsd:element ref="PostalCode" minOccurs="0"/>
> 			<xsd:element ref="CountryCode" minOccurs="0"/>
> 		</xsd:sequence>
> 		<xsd:attribute name="languageCode" type="LanguageCodeContentType"
> use="optional"/>
> 		<xsd:attribute name="type" type="NormalizedStringType"/>
> 	</xsd:complexType>
> 	<xsd:complexType name="AddressType">
> 		<xsd:complexContent>
> 			<xsd:extension base="AddressBaseType">
> 				<xsd:sequence>
> 					<xsd:element ref="ExtraInfo" minOccurs="0"/>
> 				</xsd:sequence>
> 			</xsd:extension>
> 		</xsd:complexContent>
> 	</xsd:complexType>
> 	<xsd:element name="Address" type="AddressType"/>
> 
> Here's my simple POJO:
> 
> public class Address {
> 	private String addressLine1;
> 	private String addressLine2;
> 	private String attentionOfName;
> 	private String careOfName;
> 	private String city;
> 	private String countryCode;
> 	private String postalCode;
> 	private String state;
> }
> 
> When I map my Address class, I set its schema context to the AddressType.
> 
> Then I choose the XML Direct method to map "addressLine1" as
> "LineOne/text()", and "city" as "CityName/text()", etc.
> 
> However, I get a bunch of errors like these:
> 
> OxDirectMappingNode[006F97CF] (MWXmlDirectMapping[014B9EEB]
> (addressLine1))	0811	The XPath "LineOne/text()" cannot be resolved in this
> context.
> 
> OxDirectMappingNode[01536ECF] (MWXmlDirectMapping[01B72ADA] (city))	0811
> The XPath "CityName/text()" cannot be resolved in this context.
> 
> This is very strange because if the WorkBench can see the subelement's
> fields correctly and let me select them, why can't the XPath be resolved? 
> I am also not sure what these error codes mean.  I Googled for them but
> can't find anything.
> 
> The only fields that I am allowed to map are Address schema type's
> attribute fields (such as @languageCode).  I also tried to map some other
> schema types, and the only kind of mapping that is working for me is when
> I map the class to the type's own text and attributes.  The subelement
> thing just isn't working.  Is this supposed to work?
> 
> I also noticed that the EclipseLink Workbench reports a problem with the
> schema (I obfuscated the namespace URL):
> 
> XmlSchemaNode[016F544E] (MWXmlSchema[01E0E010] (Components))	0800	Prefix
> required for namespace "http://foo.org/bar/9/baz/1.1";.
> 
> What does this mean?  I didn't actually write the schema and I know that
> it's rather complicated and includes other schemas, but the AddressType
> information is all in this schema.  How do I get this mapping to work?  
> 
> Thanks so much for your help!
> 
> --Polly
> 

-- 
View this message in context: http://www.nabble.com/MOXy%3A--Mapping-to-a-Text-Node-in-a-Subelement-tp17518097p17538036.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top