Home » Modeling » EMF » How to deserialize XML to xml schema EMF model objects
| | |
Re: How to deserialize XML to xml schema EMF model objects [message #643712 is a reply to message #643687] |
Tue, 07 December 2010 23:22 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
Tom,
Comments below.
Tom H wrote:
>
> ah, that was after many code changes I was bound to mess it up. The
> actual problem was Caused by:
> org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
> 'CompanyDetails' not found. (file:///C:/test.xml, 2, 268)
>
> I have worked out that the problem is actually to do with the namespaces.
>
> The provided xml comes with a default xmlns;
> <?xml version="1.0" encoding="ASCII"?>
> <CompanyDetails xmlns="http://xmlgw.companieshouse.gov.uk/v1-0/schema"
Whenever I see this I always say to myself, oh oh, do they really want
all elements in this document to be implicitly qualified? Probably not...
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://xmlgw.companieshouse.gov.uk/v1-0/schema
> http://xmlgw.companieshouse.gov.uk/v1-0/schema/CompanyDetail s-v2-1.xsd">
> <CompanyName>MILLENNIUM STADIUM PLC</CompanyName>
> <CompanyNumber>03176906</CompanyNumber>
> <RegAddress>
> ..
> </CompanyDetails>
>
> if I remove that
> "xmlns="http://xmlgw.companieshouse.gov.uk/v1-0/schema"" attribute
> from the xml it processes fine.
What's the target namespace of the schema? How does EMF serialize
instances?
> I have the package registered in the plug-in.xml fle with the correct
> uri;
>
> <extension point="org.eclipse.emf.ecore.generated_package">
> <package
> uri="http://xmlgw.companieshouse.gov.uk/v1-0/schema"
> class="ChbaseV21.ChbaseV21Package"
> genModel="schema/ChbaseV21.genmodel"/>
> </extension>
>
> The generated package has the following namespace, prefix,
> public interface ChbaseV21Package extends EPackage {
> String eNAME = "ChbaseV21";
> String eNS_URI = "http://xmlgw.companieshouse.gov.uk/v1-0/schema";
> String eNS_PREFIX = "";
>
> and i have tried with the PREFIX set to "" or "ChbaseV21"
You'd normally change that in the Ecore model or with annotations in the
schema...
>
> any ideas what I have wrong with the prefix/namespace settings?
Not without seeing the schema...
Oh, I guess I can follow the schema location. It's a no target
namespace schema. So nothing should be qualified, including the root
element.
>
> Thanks,
> T
>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: How to deserialize XML to xml schema EMF model objects [message #643732 is a reply to message #643712] |
Wed, 08 December 2010 05:05 |
Tom H Messages: 139 Registered: July 2009 |
Senior Member |
|
|
So for completeness, here is the XML document fragment that companies house sends back in reply to a request for CompanyDetails;
<CompanyDetails xmlns="http://xmlgw.companieshouse.gov.uk/v1-0/schema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlgw.companieshouse.gov.uk/v1-0/schema http://xmlgw.companieshouse.gov.uk/v1-0/schema/CompanyDetails-v2-1.xsd">
<CompanyName>MILLENNIUM STADIUM PLC</CompanyName>
<CompanyNumber>03176906</CompanyNumber>
<RegAddress>
<AddressLine>MILLENNIUM STADIUM</AddressLine>
<AddressLine>WESTGATE STREET</AddressLine>
<AddressLine>CARDIFF</AddressLine>
<AddressLine>CF10 1NS</AddressLine>
</RegAddress>
<CompanyCategory>Public Limited Company</CompanyCategory>
<CompanyStatus>Active</CompanyStatus>
<CountryOfOrigin>United Kingdom</CountryOfOrigin>
<RegDateType>0</RegDateType>
<IncorporationDate>1996-03-25</IncorporationDate>
<Accounts>
<AccountRefDate>30-06</AccountRefDate>
<NextDueDate>2011-12-31</NextDueDate>
<Overdue>NO</Overdue>
<LastMadeUpDate>2010-06-30</LastMadeUpDate>
<AccountCategory>FULL</AccountCategory>
<DocumentAvailable>1</DocumentAvailable>
</Accounts>
<Returns>
<NextDueDate>2011-04-22</NextDueDate>
<Overdue>NO</Overdue>
<LastMadeUpDate>2010-03-25</LastMadeUpDate>
<DocumentAvailable>1</DocumentAvailable>
</Returns>
<SICCodes>
<SicText>9261 - Operate sports arenas & stadiums</SicText>
</SICCodes>
<LastFullMemDate>2010-03-25</LastFullMemDate>
<HasUKestablishment>0</HasUKestablishment>
<HasAppointments>1</HasAppointments>
<InLiquidation>0</InLiquidation>
</CompanyDetails>
and here is the xml schema document that I used to generate my model;
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2005 rel. 3 U (http://www.altova.com) by Companies House (Companies House) -->
<!-- Companies House XML Gateway Schema -->
<!-- $Id: CompanyDetails-v2-1.xsd,v 1.3 2009-03-24 10:03:11 ecrockford Exp $ -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:chg="http://xmlgwdev.companieshouse.gov.uk" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="chbase-v2-1.xsd"/>
<xs:element name="CompanyDetails">
<xs:annotation>
<xs:documentation>Company Details Information</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="CompanyName"/>
<xs:element ref="CompanyNumber"/>
<xs:element name="HasInconsistencies" type="xs:boolean" minOccurs="0">
<xs:annotation>
<xs:documentation>The Company data has inconsistencies</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element ref="RegAddress"/>
<xs:element ref="CompanyCategory"/>
<xs:element ref="CompanyStatus"/>
<xs:element ref="CountryOfOrigin"/>
<xs:element ref="RegistrationDate" minOccurs="0"/>
<xs:element name="RegDateType">
<xs:annotation>
<xs:documentation>Whether the Company has a Registration or Incorporation Date</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element ref="DissolutionDate" minOccurs="0"/>
<xs:element ref="IncorporationDate" minOccurs="0"/>
<xs:element ref="ClosureDate" minOccurs="0"/>
<xs:element ref="PreviousNames" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="Accounts">
<xs:annotation>
<xs:documentation>Container for Annual Accounts Information</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="AccountRefDate" minOccurs="0"/>
<xs:element ref="NextDueDate" minOccurs="0"/>
<xs:element ref="Overdue"/>
<xs:element ref="LastMadeUpDate" minOccurs="0"/>
<xs:element ref="AccountCategory" minOccurs="0"/>
<xs:element ref="DocumentAvailable"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Returns">
<xs:annotation>
<xs:documentation>Container for Annual Return Information</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="NextDueDate" minOccurs="0"/>
<xs:element ref="Overdue"/>
<xs:element ref="LastMadeUpDate" minOccurs="0"/>
<xs:element ref="DocumentAvailable"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Mortgages" minOccurs="0">
<xs:annotation>
<xs:documentation>Container for Mortgage Information</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="MortgageInd"/>
<xs:element ref="NumMortCharges"/>
<xs:element ref="NumMortOutstanding"/>
<xs:element ref="NumMortPartSatisfied"/>
<xs:element ref="NumMortSatisfied"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element ref="SICCodes"/>
<xs:element ref="LastFullMemDate" minOccurs="0"/>
<xs:element ref="LastBulkShareDate" minOccurs="0"/>
<xs:element ref="WeededDate" minOccurs="0"/>
<xs:element ref="HasUKestablishment"/>
<xs:element ref="HasAppointments"/>
<xs:element ref="InLiquidation"/>
<xs:element name="LimitedPartnerships" minOccurs="0">
<xs:annotation>
<xs:documentation>Container for Limited Partnerships Specific Information</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="NumGenPartners"/>
<xs:element ref="NumLimPartners"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CompanyDetailsRequest">
<xs:annotation>
<xs:documentation>Company Details Request</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="CompanyNumber"/>
<xs:element ref="GiveMortTotals" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
So there is no targetnamespace in the schema
Quote: |
Oh, I guess I can follow the schema location. It's a no target
namespace schema. So nothing should be qualified, including the root
element.
|
when you say nothing should be qualified, does that mean that the prefix should be "" in the ecore file and the generated java annotations?
or that the xml files should not have prefixes on elements?
or that the xml files should not have default namespace provided?
If I serialize a generated core object using code like this;
try { ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.createResource(URI.createURI("http:///My.chbasev21"));
DocumentRoot documentRoot = ChbaseV21Factory.eINSTANCE.createDocumentRoot();
CompanyDetailsType root = ChbaseV21Factory.eINSTANCE.createCompanyDetailsType();
documentRoot.setCompanyDetails(root);
resource.getContents().add(documentRoot);
//resource.save(Collections.EMPTY_MAP);
resource.save(System.out, null);
resource.save(new FileOutputStream("C:/test2.xml"), null);
}
catch (IOException exception) {
exception.printStackTrace();
}
it results in output like this;
<?xml version="1.0" encoding="ASCII"?>
<CompanyDetails/>
so I guess that my model does not know about the default namespace that is coming back with the XML files from the service.
How is this achieved, by adding the namespace explicitly to generated objects or somehow in the ecore mapping?
Thanks,
T
|
|
|
Re: How to deserialize XML to xml schema EMF model objects [message #643739 is a reply to message #643732] |
Wed, 08 December 2010 06:28 |
Tom H Messages: 139 Registered: July 2009 |
Senior Member |
|
|
So from this website;
"http: //msdn.microsoft.com/en-us/library/aa258639%28SQL.80%29.aspx " | You can use the xsd:targetNamespace attribute to place elements and attributes from the default namespace into a different namespace. You can also specify whether the locally declared elements and attributes of the schema should appear qualified by a namespace, either explicitly by using a prefix or implicitly by default. You can use the elementFormDefault and attributeFormDefault attributes on the <xsd:schema> element to globally specify the qualification of local elements and attributes, or you can use the form attribute to specify individual elements and attributes separately."
|
So this appears to be saying that if an schema provides a targetNamespace attribute, elements and attributes from the default namespace in the xml eg <mynode> are placed into some namespace. So if targetnamespace="urn:somenamespace" then if the xml file did not provide a default namespace at least there would be a default to look for the generated packages in???
This seems to suggest the ecore that was derived from the xsd above which has qualified "false"; might be the problem
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="qualified" value="false"/>
</eAnnotations>
Should be set to true, otherwise serialization will produce unqualified elements and the schema has specified no targetnamespace for default elements.
Anyway if I set this to true and regenerate the model, serialized xml has a default namespace eg;
<?xml version="1.0" encoding="ASCII"?>
<CompanyDetails xmlns="http://xmlgw.companieshouse.gov.uk/v1-0/schema"/>
and the deserialization of the remotely provided XML is now failing due to a
Caused by: java.lang.UnsupportedOperationException
at ChbaseV21.impl.RegAddressTypeImpl.getAddressLine(RegAddressTypeImpl.java:179)"
http://msdn.microsoft.com/en-us/library/aa258639%28SQL.80%29 .aspx
http://www.xfront.com/DefaultNamespace.pdf
http://www.stylusstudio.com/w3c/schema0/NS.htm#NS
http://geekswithblogs.net/dmillard/archive/2004/10/20/12935. aspx
[Updated on: Wed, 08 December 2010 06:31] Report message to a moderator
|
|
|
Re: How to deserialize XML to xml schema EMF model objects [message #643828 is a reply to message #643732] |
Wed, 08 December 2010 12:53 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
Tom,
Comments below.
Tom H wrote:
> So for completeness, here is the XML document fragment that companies
> house sends back in reply to a request for CompanyDetails;
>
>
> <CompanyDetails
> xmlns="http://xmlgw.companieshouse.gov.uk/v1-0/schema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
> xsi:schemaLocation="http://xmlgw.companieshouse.gov.uk/v1-0/schema
> http://xmlgw.companieshouse.gov.uk/v1-0/schema/CompanyDetail s-v2-1.xsd">
> <CompanyName>MILLENNIUM STADIUM PLC</CompanyName>
> <CompanyNumber>03176906</CompanyNumber>
> <RegAddress>
> <AddressLine>MILLENNIUM STADIUM</AddressLine>
> <AddressLine>WESTGATE STREET</AddressLine>
> <AddressLine>CARDIFF</AddressLine>
> <AddressLine>CF10 1NS</AddressLine>
> </RegAddress>
> <CompanyCategory>Public Limited Company</CompanyCategory>
> <CompanyStatus>Active</CompanyStatus>
> <CountryOfOrigin>United Kingdom</CountryOfOrigin>
> <RegDateType>0</RegDateType>
> <IncorporationDate>1996-03-25</IncorporationDate>
> <Accounts>
> <AccountRefDate>30-06</AccountRefDate>
> <NextDueDate>2011-12-31</NextDueDate>
> <Overdue>NO</Overdue>
> <LastMadeUpDate>2010-06-30</LastMadeUpDate>
> <AccountCategory>FULL</AccountCategory>
> <DocumentAvailable>1</DocumentAvailable>
> </Accounts>
> <Returns>
> <NextDueDate>2011-04-22</NextDueDate>
> <Overdue>NO</Overdue>
> <LastMadeUpDate>2010-03-25</LastMadeUpDate>
> <DocumentAvailable>1</DocumentAvailable>
> </Returns>
> <SICCodes>
> <SicText>9261 - Operate sports arenas &
> stadiums</SicText>
> </SICCodes>
> <LastFullMemDate>2010-03-25</LastFullMemDate>
> <HasUKestablishment>0</HasUKestablishment>
> <HasAppointments>1</HasAppointments>
> <InLiquidation>0</InLiquidation>
> </CompanyDetails>
>
>
> and here is the xml schema document that I used to generate my model;
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!-- edited with XMLSpy v2005 rel. 3 U (http://www.altova.com) by
> Companies House (Companies House) -->
> <!-- Companies House XML Gateway Schema -->
> <!-- $Id: CompanyDetails-v2-1.xsd,v 1.3 2009-03-24 10:03:11 ecrockford
> Exp $ -->
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:chg="http://xmlgwdev.companieshouse.gov.uk"
> elementFormDefault="qualified" attributeFormDefault="unqualified">
> <xs:include schemaLocation="chbase-v2-1.xsd"/>
> <xs:element name="CompanyDetails">
> <xs:annotation>
> <xs:documentation>Company Details
> Information</xs:documentation>
> </xs:annotation>
> <xs:complexType>
>
> <xs:sequence>
> <xs:element ref="CompanyName"/>
> <xs:element ref="CompanyNumber"/>
> <xs:element name="HasInconsistencies"
> type="xs:boolean" minOccurs="0">
> <xs:annotation>
> <xs:documentation>The Company data has
> inconsistencies</xs:documentation>
> </xs:annotation>
> </xs:element>
>
> <xs:element ref="RegAddress"/>
> <xs:element ref="CompanyCategory"/>
> <xs:element ref="CompanyStatus"/>
> <xs:element ref="CountryOfOrigin"/>
> <xs:element ref="RegistrationDate" minOccurs="0"/>
> <xs:element name="RegDateType">
> <xs:annotation>
> <xs:documentation>Whether the Company has a
> Registration or Incorporation Date</xs:documentation>
>
> </xs:annotation>
> </xs:element>
> <xs:element ref="DissolutionDate" minOccurs="0"/>
> <xs:element ref="IncorporationDate" minOccurs="0"/>
> <xs:element ref="ClosureDate" minOccurs="0"/>
> <xs:element ref="PreviousNames" minOccurs="0"
> maxOccurs="unbounded"/>
> <xs:element name="Accounts">
> <xs:annotation>
> <xs:documentation>Container for Annual
> Accounts Information</xs:documentation>
>
> </xs:annotation>
> <xs:complexType>
> <xs:sequence>
> <xs:element ref="AccountRefDate"
> minOccurs="0"/>
> <xs:element ref="NextDueDate" minOccurs="0"/>
> <xs:element ref="Overdue"/>
> <xs:element ref="LastMadeUpDate"
> minOccurs="0"/>
> <xs:element ref="AccountCategory"
> minOccurs="0"/>
> <xs:element ref="DocumentAvailable"/>
>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element name="Returns">
> <xs:annotation>
> <xs:documentation>Container for Annual Return
> Information</xs:documentation>
> </xs:annotation>
> <xs:complexType>
>
> <xs:sequence>
> <xs:element ref="NextDueDate" minOccurs="0"/>
> <xs:element ref="Overdue"/>
> <xs:element ref="LastMadeUpDate"
> minOccurs="0"/>
> <xs:element ref="DocumentAvailable"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element name="Mortgages" minOccurs="0">
>
> <xs:annotation>
> <xs:documentation>Container for Mortgage
> Information</xs:documentation>
> </xs:annotation>
> <xs:complexType>
> <xs:sequence>
> <xs:element ref="MortgageInd"/>
> <xs:element ref="NumMortCharges"/>
> <xs:element ref="NumMortOutstanding"/>
>
> <xs:element ref="NumMortPartSatisfied"/>
> <xs:element ref="NumMortSatisfied"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element ref="SICCodes"/>
> <xs:element ref="LastFullMemDate" minOccurs="0"/>
> <xs:element ref="LastBulkShareDate" minOccurs="0"/>
> <xs:element ref="WeededDate" minOccurs="0"/>
>
> <xs:element ref="HasUKestablishment"/>
> <xs:element ref="HasAppointments"/>
> <xs:element ref="InLiquidation"/>
> <xs:element name="LimitedPartnerships" minOccurs="0">
> <xs:annotation>
> <xs:documentation>Container for Limited
> Partnerships Specific Information</xs:documentation>
> </xs:annotation>
> <xs:complexType>
>
> <xs:sequence>
> <xs:element ref="NumGenPartners"/>
> <xs:element ref="NumLimPartners"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
>
> <xs:element name="CompanyDetailsRequest">
> <xs:annotation>
> <xs:documentation>Company Details Request</xs:documentation>
> </xs:annotation>
> <xs:complexType>
> <xs:sequence>
> <xs:element ref="CompanyNumber"/>
> <xs:element ref="GiveMortTotals" minOccurs="0"/>
>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:schema>
>
>
>
>
> So there is no targetnamespace in the schema
>
> Quote:
>> Oh, I guess I can follow the schema location. It's a no target
>> namespace schema. So nothing should be qualified, including the root
>> element.
>
>
> when you say nothing should be qualified, does that mean that the
> prefix should be "" in the ecore file and the generated java annotations?
No, that the namespace of the elements and attributes must be null.
I.e., as if xmlns="" appears in the document.
>
> or that the xml files should not have prefixes on elements?
Not only no prefixes, but also no xmlns="<non-empty>".
>
> or that the xml files should not have default namespace provided?
Both.
>
>
> If I serialize a generated core object using code like this;
>
>
> try { ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource =
> resourceSet.createResource(URI.createURI("http:///My.chbasev21"));
> DocumentRoot documentRoot =
> ChbaseV21Factory.eINSTANCE.createDocumentRoot();
> CompanyDetailsType root =
> ChbaseV21Factory.eINSTANCE.createCompanyDetailsType();
> documentRoot.setCompanyDetails(root);
> resource.getContents().add(documentRoot);
> //resource.save(Collections.EMPTY_MAP);
> resource.save(System.out, null);
> resource.save(new FileOutputStream("C:/test2.xml"), null);
> }
> catch (IOException exception) {
> exception.printStackTrace();
> }
>
>
> it results in output like this;
>
>
> <?xml version="1.0" encoding="ASCII"?>
> <CompanyDetails/>
Yes, that's correct.
>
>
> so I guess that my model does not know about the default namespace
> that is coming back with the XML files from the service.
The XML you show doesn't conform to the schema.
>
> How is this achieved, by adding the namespace explicitly to generated
> objects or somehow in the ecore mapping?
Change the schema to accurately describe the XML you're consuming or
change the XML to conform to the schema you've described.
>
> Thanks,
> T
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: How to deserialize XML to xml schema EMF model objects [message #643833 is a reply to message #643739] |
Wed, 08 December 2010 13:08 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------060003050006020304070006
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Tom,
Comments below.
Tom H wrote:
> So from this website;
>
>
> "http: //msdn.microsoft.com/en-us/library/aa258639%28SQL.80%29.aspx "
>> You can use the xsd:targetNamespace attribute to place elements and
>> attributes from the default namespace into a different namespace. You
>> can also specify whether the locally declared elements and attributes
>> of the schema should appear qualified by a namespace, either
>> explicitly by using a prefix or implicitly by default. You can use
>> the elementFormDefault and attributeFormDefault attributes on the
>> <xsd:schema> element to globally specify the qualification of local
>> elements and attributes, or you can use the form attribute to specify
>> individual elements and attributes separately."
>
>
> So this appears to be saying that if an schema provides a
> targetNamespace attribute, elements and attributes from the default
> namespace in the xml eg <mynode> are placed into some namespace.
No. The above statement is purely about the namespaces of elements and
attributes defined in the schema. In all cases, every element and
attribute logically consists of a namespace/name pair. That namespace
might be null or "" (which are treated as equivalent), but logically
it's always a pair.
> So if elementFormdefault="qualified" then if the xml file did not
> provide a default namespace at least there would be a default to look
> for the generated packages in???
No. Again this is purely a statement about the schema. This says that
local element and attribute declarations (those not at the top level of
the schema but rather in complex types or element/attribute groups) will
normally has null/"" namespace, but with th element/attribute form
default attribute or a local form attribute on the declaration they can
specify that the namespace instead of being null is the target namespace
of the schema.
Of course when the target namespace is already null/"" it's rather
pointless to talk about whether the local elements/attribute are
qualified or not because all the elements and attribute local or
otherwise will name null/"" as the namespace in the pair regardless of
the form declarations.
>
> This seems to suggest the ecore that was derived from the xsd above
> which has qualified "false"; might be the problem
>
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="qualified" value="false"/>
> </eAnnotations>
No. EMF requires a package to have a unique nsURI which normally
corresponds to the schema's target namespace. When there isn't a target
namespace, there still needs to be an nsURI and this annotation
effectively tells the serializer/deserializer that this namespace is not
to be used for qualification.
>
>
> Should be set to true, otherwise serialization will produce
> unqualified elements and the schema has specified no targetnamespace
> for default elements.
It should be set to ensure that instance match the schema.
>
> Anyway if I set this to true and regenerate the model, serialized xml
> has a default namespace eg;
>
> <?xml version="1.0" encoding="ASCII"?>
> <CompanyDetails xmlns="http://xmlgw.companieshouse.gov.uk/v1-0/schema"/>
>
>
> and the deserialization of the remotely provided XML is now failing
> due to a
> Caused by: java.lang.UnsupportedOperationException
> at
> ChbaseV21.impl.RegAddressTypeImpl.getAddressLine(RegAddressT ypeImpl.java:179) "
>
For me this method looks like this:
public EList<String> getAddressLine()
{
return
getGroup().list(ChbaseV21Package.Literals.REG_ADDRESS_TYPE__ ADDRESS_LINE);
}
Have you been editing the Ecore model after importing it from the schema?
>
>
>
> http://msdn.microsoft.com/en-us/library/aa258639%28SQL.80%29 .aspx
> http://www.xfront.com/DefaultNamespace.pdf
> http://www.stylusstudio.com/w3c/schema0/NS.htm#NS
> http://geekswithblogs.net/dmillard/archive/2004/10/20/12935. aspx
--------------060003050006020304070006
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Tom,<br>
<br>
Comments below.<br>
<br>
<br>
Tom H wrote:
<blockquote cite="mid:idn89n$n37$1@news.eclipse.org" type="cite">So
from this website;
<br>
<br>
<br>
"http: //msdn.microsoft.com/en-us/library/aa258639%28SQL.80%29.aspx "
<br>
<blockquote type="cite">You can use the xsd:targetNamespace attribute
to place elements and attributes from the default namespace into a
different namespace. You can also specify whether the locally declared
elements and attributes of the schema should appear qualified by a
namespace, either explicitly by using a prefix or implicitly by
default. You can use the elementFormDefault and attributeFormDefault
attributes on the <xsd:schema> element to globally specify the
qualification of local elements and attributes, or you can use the form
attribute to specify individual elements and attributes separately."
<br>
</blockquote>
<br>
<br>
So this appears to be saying that if an schema provides a
targetNamespace attribute, elements and attributes from the default
namespace in the xml eg <mynode> are placed into some namespace.</blockquote>
No. The above statement is purely about the namespaces of elements and
attributes defined in the schema. In all cases, every element and
attribute logically consists of a namespace/name pair. That namespace
might be null or "" (which are treated as equivalent), but logically
it's always a pair.<br>
<blockquote cite="mid:idn89n$n37$1@news.eclipse.org" type="cite"> So if
elementFormdefault="qualified" then if the xml file did not provide a
default namespace at least there would be a default to look for the
generated packages in???
<br>
</blockquote>
No. Again this is purely a statement about the schema. This says that
local element and attribute declarations (those not at the top level of
the schema but rather in complex types or element/attribute groups)
will normally has null/"" namespace, but with th element/attribute form
default attribute or a local form attribute on the declaration they can
specify that the namespace instead of being null is the target
namespace of the schema.<br>
<br>
Of course when the target namespace is already null/"" it's rather
pointless to talk about whether the local elements/attribute are
qualified or not because all the elements and attribute local or
otherwise will name null/"" as the namespace in the pair regardless of
the form declarations.<br>
<blockquote cite="mid:idn89n$n37$1@news.eclipse.org" type="cite">
<br>
This seems to suggest the ecore that was derived from the xsd above
which has qualified "false"; might be the problem
<br>
<br>
<eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>>
<br>
<details key="qualified" value="false"/>
<br>
</eAnnotations>
<br>
</blockquote>
No. EMF requires a package to have a unique nsURI which normally
corresponds to the schema's target namespace. When there isn't a
target namespace, there still needs to be an nsURI and this annotation
effectively tells the serializer/deserializer that this namespace is
not to be used for qualification.<br>
<blockquote cite="mid:idn89n$n37$1@news.eclipse.org" type="cite"><br>
<br>
Should be set to true, otherwise serialization will produce unqualified
elements and the schema has specified no targetnamespace for default
elements.
<br>
</blockquote>
It should be set to ensure that instance match the schema.<br>
<blockquote cite="mid:idn89n$n37$1@news.eclipse.org" type="cite"><br>
Anyway if I set this to true and regenerate the model, serialized xml
has a default namespace eg;
<br>
<br>
<?xml version="1.0" encoding="ASCII"?>
<br>
<CompanyDetails
xmlns=<a class="moz-txt-link-rfc2396E" href="http://xmlgw.companieshouse.gov.uk/v1-0/schema">"http://xmlgw.companieshouse.gov.uk/v1-0/schema"</a>/>
<br>
<br>
<br>
and the deserialization of the remotely provided XML is now failing due
to a <br>
Caused by: java.lang.UnsupportedOperationException
<br>
at
ChbaseV21.impl.RegAddressTypeImpl.getAddressLine(RegAddressT ypeImpl.java:179) "
<br>
</blockquote>
For me this method looks like this: <br>
<br>
<small> public EList<String> getAddressLine()<br>
{<br>
return
getGroup().list(ChbaseV21Package.Literals.REG_ADDRESS_TYPE__ ADDRESS_LINE); <br>
}<br>
</small><br>
Have you been editing the Ecore model after importing it from the
schema?<br>
<blockquote cite="mid:idn89n$n37$1@news.eclipse.org" type="cite"><br>
<br>
<br>
<a class="moz-txt-link-freetext" href=" http://msdn.microsoft.com/en-us/library/aa258639%28SQL.80%29 .aspx"> http://msdn.microsoft.com/en-us/library/aa258639%28SQL.80%29 .aspx</a>
<br>
<a class="moz-txt-link-freetext" href="http://www.xfront.com/DefaultNamespace.pdf">http://www.xfront.com/DefaultNamespace.pdf</a>
<br>
<a class="moz-txt-link-freetext" href="http://www.stylusstudio.com/w3c/schema0/NS.htm#NS">http://www.stylusstudio.com/w3c/schema0/NS.htm#NS</a>
<br>
<a class="moz-txt-link-freetext" href=" http://geekswithblogs.net/dmillard/archive/2004/10/20/12935. aspx"> http://geekswithblogs.net/dmillard/archive/2004/10/20/12935. aspx</a>
<br>
</blockquote>
</body>
</html>
--------------060003050006020304070006--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Goto Forum:
Current Time: Fri Apr 26 01:09:21 GMT 2024
Powered by FUDForum. Page generated in 0.03783 seconds
|