It is common for an XML document to include one or more namespaces. TopLink supports this using its NamespaceResolver. The namespace resolver maintains pairs of namespace prefixes and URIs. TopLink uses these prefixes in conjunction with the XPath statements you specify on EIS mappings to XML records and XML mappings.
Although TopLink captures namespace prefixes in the XPath statements for mappings (if applicable), the input document is not required to use the same namespace prefixes. TopLink will use the namespace prefixes specified in the mapping when creating new documents.
Code Sample
NamespaceResolver resolver = new NamespaceResolver();
@see org.eclipse.persistence.oxm.XMLDescriptor
@see org.eclipse.persistence.eis.EISDescriptor
resolver.put( "ns", "urn:namespace-example");
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Customer.class);
descriptor.setDefaultRootElement("ns:customer");
descriptor.setNamespaceResolver(resolver);
XMLDirectMapping mapping = new XMLDirectMapping();
mapping.setAttributeName("id");
mapping.setXPath("ns:id/text()");
descriptor.addMapping(mapping);
It is common for an XML document to include one or more namespaces. TopLink supports this using its NamespaceResolver. The namespace resolver maintains pairs of namespace prefixes and URIs. TopLink uses these prefixes in conjunction with the XPath statements you specify on EIS mappings to XML records and XML mappings.
Although TopLink captures namespace prefixes in the XPath statements for mappings (if applicable), the input document is not required to use the same namespace prefixes. TopLink will use the namespace prefixes specified in the mapping when creating new documents.
Code Sample
NamespaceResolver resolver = new NamespaceResolver();
@see org.eclipse.persistence.oxm.XMLDescriptor
@see org.eclipse.persistence.eis.EISDescriptor
resolver.put( "ns", "urn:namespace-example");
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Customer.class);
descriptor.setDefaultRootElement("ns:customer");
descriptor.setNamespaceResolver(resolver);
XMLDirectMapping mapping = new XMLDirectMapping();
mapping.setAttributeName("id");
mapping.setXPath("ns:id/text()");
descriptor.addMapping(mapping);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|