Skip to main content

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

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-tp17518097p17518097.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top