xsi:type is duplicated in the xml after using toXml :(

182 views
Skip to first unread message

deanhiller

unread,
Oct 20, 2011, 2:31:26 PM10/20/11
to scalaxb
I have the following code

val normalizedEvent :EPCISEventType = fromXML[EPCISEventType](xml)
val temp = toXML(normalizedEvent)

where EPCISEventType is a child of a main document/xsd.
unfortunately, the results of temp are different than the xml fed in
because there is two definitions of xsi:type and then the java xml
parsers then choke and complain about two definitions of xsi:type.

Both xsi:type attributes name the same object though. Any ideas what
is wrong?

I have seen some examples on the web that do a
normalizedEvent.toXML......how do I do that? Is there some implicit
functions I need to import?

thanks,
Dean

eugene yokota

unread,
Oct 20, 2011, 2:35:29 PM10/20/11
to sca...@googlegroups.com
Hi Dean,

Could you point me to the xsd that you are using?

-eugene

deanhiller

unread,
Oct 20, 2011, 3:42:45 PM10/20/11
to scalaxb
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:epcis="urn:epcglobal:epcis:xsd:1" xmlns:sbdh="http://
www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"
xmlns:epcglobal="urn:epcglobal:xsd:1" xmlns:xsd="http://www.w3.org/
2001/XMLSchema" targetNamespace="urn:epcglobal:epcis:xsd:1"
elementFormDefault="unqualified" attributeFormDefault="unqualified"
version="1.0">
<xsd:annotation>
<xsd:documentation xml:lang="en">
<epcglobal:copyright>Copyright (C) 2006, 2005, 2004 EPCglobal Inc.,
All Rights Reserved.</epcglobal:copyright>
<epcglobal:disclaimer>EPCglobal Inc., its members, officers,
directors, employees, or agents shall not be liable for any injury,
loss, damages, financial or otherwise, arising from, related to, or
caused by the use of this document. The use of said document shall
constitute your express consent to the foregoing exculpation.</
epcglobal:disclaimer>
<epcglobal:specification>EPC INFORMATION SERVICE (EPCIS) Version
1.0</epcglobal:specification>
</xsd:documentation>
</xsd:annotation>
<xsd:import namespace="urn:epcglobal:xsd:1" schemaLocation="./
EPCglobal.xsd"/>
<xsd:import namespace="http://www.unece.org/cefact/namespaces/
StandardBusinessDocumentHeader" schemaLocation="./
StandardBusinessDocumentHeader.xsd"/>
<!-- EPCIS CORE ELEMENTS -->
<xsd:element name="EPCISDocument" type="epcis:EPCISDocumentType"/>
<xsd:complexType name="EPCISDocumentType">
<xsd:annotation>
<xsd:documentation xml:lang="en">
document that contains a Header and a Body.
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="epcglobal:Document">
<xsd:sequence>
<xsd:element name="EPCISHeader" type="epcis:EPCISHeaderType"
minOccurs="0"/>
<xsd:element name="EPCISBody" type="epcis:EPCISBodyType"/>
<xsd:element name="extension"
type="epcis:EPCISDocumentExtensionType" minOccurs="0"/>
<xsd:any namespace="##other" processContents="lax" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="EPCISHeaderType">
<xsd:annotation>
<xsd:documentation xml:lang="en">
specific header(s) including the Standard Business Document Header.
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element ref="sbdh:StandardBusinessDocumentHeader"/>
<xsd:element name="extension" type="epcis:EPCISHeaderExtensionType"
minOccurs="0"/>
<xsd:any namespace="##other" processContents="lax" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:complexType>
<xsd:complexType name="EPCISBodyType">
<xsd:annotation>
<xsd:documentation xml:lang="en">
specific body that contains EPCIS related Events.
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="EventList" type="epcis:EventListType"
minOccurs="0"/>
<xsd:element name="extension" type="epcis:EPCISBodyExtensionType"
minOccurs="0"/>
<xsd:any namespace="##other" processContents="lax" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:complexType>
<!-- EPCIS CORE ELEMENT TYPES -->
<xsd:complexType name="EventListType">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="ObjectEvent" type="epcis:ObjectEventType"
minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="AggregationEvent"
type="epcis:AggregationEventType" minOccurs="0" maxOccurs="unbounded"/
>
<xsd:element name="QuantityEvent" type="epcis:QuantityEventType"
minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="TransactionEvent"
type="epcis:TransactionEventType" minOccurs="0" maxOccurs="unbounded"/
>
<xsd:element name="extension"
type="epcis:EPCISEventListExtensionType"/>
<xsd:any namespace="##other" processContents="lax"/>
</xsd:choice>
<!-- Note: the use of "unbounded" in both the xsd:choice element
and the enclosed xsd:element elements is, strictly
speaking,
redundant. However, this was found to avoid
problems with
certain XML processing tools, and so is retained
here.
-->
</xsd:complexType>
<xsd:complexType name="EPCListType">
<xsd:sequence>
<xsd:element name="epc" type="epcglobal:EPC" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="ActionType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="ADD"/>
<xsd:enumeration value="OBSERVE"/>
<xsd:enumeration value="DELETE"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="ParentIDType">
<xsd:restriction base="xsd:anyURI"/>
</xsd:simpleType>
<!-- Standard Vocabulary -->
<xsd:simpleType name="BusinessStepIDType">
<xsd:restriction base="xsd:anyURI"/>
</xsd:simpleType>
<!-- Standard Vocabulary -->
<xsd:simpleType name="DispositionIDType">
<xsd:restriction base="xsd:anyURI"/>
</xsd:simpleType>
<!-- User Vocabulary -->
<xsd:simpleType name="EPCClassType">
<xsd:restriction base="xsd:anyURI"/>
</xsd:simpleType>
<!-- User Vocabulary -->
<xsd:simpleType name="ReadPointIDType">
<xsd:restriction base="xsd:anyURI"/>
</xsd:simpleType>
<xsd:complexType name="ReadPointType">
<xsd:sequence>
<xsd:element name="id" type="epcis:ReadPointIDType"/>
<xsd:element name="extension" type="epcis:ReadPointExtensionType"
minOccurs="0"/>
<!-- The wildcard below provides the extension mechanism described
in Section 9.4 -->
<xsd:any namespace="##other" processContents="lax" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ReadPointExtensionType">
<xsd:sequence>
<xsd:any namespace="##local" processContents="lax"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:complexType>
<!-- User Vocabulary -->
<xsd:simpleType name="BusinessLocationIDType">
<xsd:restriction base="xsd:anyURI"/>
</xsd:simpleType>
<xsd:complexType name="BusinessLocationType">
<xsd:sequence>
<xsd:element name="id" type="epcis:BusinessLocationIDType"/>
<xsd:element name="extension"
type="epcis:BusinessLocationExtensionType" minOccurs="0"/>
<!-- The wildcard below provides the extension mechanism described
in Section 9.4 -->
<xsd:any namespace="##other" processContents="lax" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="BusinessLocationExtensionType">
<xsd:sequence>
<xsd:any namespace="##local" processContents="lax"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:complexType>
<!-- User Vocabulary -->
<xsd:simpleType name="BusinessTransactionIDType">
<xsd:restriction base="xsd:anyURI"/>
</xsd:simpleType>
<!-- Standard Vocabulary -->
<xsd:simpleType name="BusinessTransactionTypeIDType">
<xsd:restriction base="xsd:anyURI"/>
</xsd:simpleType>
<xsd:complexType name="BusinessTransactionType">
<xsd:simpleContent>
<xsd:extension base="epcis:BusinessTransactionIDType">
<xsd:attribute name="type"
type="epcis:BusinessTransactionTypeIDType" use="optional"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:complexType name="BusinessTransactionListType">
<xsd:sequence>
<xsd:element name="bizTransaction"
type="epcis:BusinessTransactionType" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<!-- items listed alphabetically by name -->
<!-- Some element types accommodate extensibility in the manner of
"Versioning XML Vocabularies" by David Orchard (see
http://www.xml.com/pub/a/2003/12/03/versioning.html).

In this approach, an optional <extension> element is defined
for each extensible element type, where an <extension> element
may contain future elements defined in the target namespace.

In addition to the optional <extension> element, extensible
element
types are declared with a final xsd:any wildcard to
accommodate
future elements defined by third parties (as denoted by the
##other
namespace).

Finally, the xsd:anyAttribute facility is used to allow
arbitrary
attributes to be added to extensible element types. -->
<xsd:complexType name="EPCISEventType" abstract="true">
<xsd:annotation>
<xsd:documentation xml:lang="en">
base type for all EPCIS events.
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="eventTime" type="xsd:dateTime"/>
<xsd:element name="recordTime" type="xsd:dateTime" minOccurs="0"/>
<xsd:element name="eventTimeZoneOffset" type="xsd:string"/>
<xsd:element name="baseExtension"
type="epcis:EPCISEventExtensionType" minOccurs="0"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:complexType>
<xsd:complexType name="ObjectEventType">
<xsd:annotation>
<xsd:documentation xml:lang="en">
Object Event captures information about an event pertaining to one
or more
objects identified by EPCs.
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="epcis:EPCISEventType">
<xsd:sequence>
<xsd:element name="epcList" type="epcis:EPCListType"/>
<xsd:element name="action" type="epcis:ActionType"/>
<xsd:element name="bizStep" type="epcis:BusinessStepIDType"
minOccurs="0"/>
<xsd:element name="disposition" type="epcis:DispositionIDType"
minOccurs="0"/>
<xsd:element name="readPoint" type="epcis:ReadPointType"
minOccurs="0"/>
<xsd:element name="bizLocation" type="epcis:BusinessLocationType"
minOccurs="0"/>
<xsd:element name="bizTransactionList"
type="epcis:BusinessTransactionListType" minOccurs="0"/>
<xsd:element name="extension"
type="epcis:ObjectEventExtensionType" minOccurs="0"/>
<xsd:any namespace="##other" processContents="lax" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="AggregationEventType">
<xsd:annotation>
<xsd:documentation xml:lang="en">
Aggregation Event captures an event that applies to objects that
have a physical association with one another.
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="epcis:EPCISEventType">
<xsd:sequence>
<xsd:element name="parentID" type="epcis:ParentIDType"
minOccurs="0"/>
<xsd:element name="childEPCs" type="epcis:EPCListType"/>
<xsd:element name="action" type="epcis:ActionType"/>
<xsd:element name="bizStep" type="epcis:BusinessStepIDType"
minOccurs="0"/>
<xsd:element name="disposition" type="epcis:DispositionIDType"
minOccurs="0"/>
<xsd:element name="readPoint" type="epcis:ReadPointType"
minOccurs="0"/>
<xsd:element name="bizLocation" type="epcis:BusinessLocationType"
minOccurs="0"/>
<xsd:element name="bizTransactionList"
type="epcis:BusinessTransactionListType" minOccurs="0"/>
<xsd:element name="extension"
type="epcis:AggregationEventExtensionType" minOccurs="0"/>
<xsd:any namespace="##other" processContents="lax" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="QuantityEventType">
<xsd:annotation>
<xsd:documentation xml:lang="en">
Quantity Event captures an event that takes place with respect to a
specified quantity of
object class.
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="epcis:EPCISEventType">
<xsd:sequence>
<xsd:element name="epcClass" type="epcis:EPCClassType"/>
<xsd:element name="quantity" type="xsd:int"/>
<xsd:element name="bizStep" type="epcis:BusinessStepIDType"
minOccurs="0"/>
<xsd:element name="disposition" type="epcis:DispositionIDType"
minOccurs="0"/>
<xsd:element name="readPoint" type="epcis:ReadPointType"
minOccurs="0"/>
<xsd:element name="bizLocation" type="epcis:BusinessLocationType"
minOccurs="0"/>
<xsd:element name="bizTransactionList"
type="epcis:BusinessTransactionListType" minOccurs="0"/>
<xsd:element name="extension"
type="epcis:QuantityEventExtensionType" minOccurs="0"/>
<xsd:any namespace="##other" processContents="lax" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="TransactionEventType">
<xsd:annotation>
<xsd:documentation xml:lang="en">
Transaction Event describes the association or disassociation of
physical objects to one or more business
transactions.
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="epcis:EPCISEventType">
<xsd:sequence>
<xsd:element name="bizTransactionList"
type="epcis:BusinessTransactionListType"/>
<xsd:element name="parentID" type="epcis:ParentIDType"
minOccurs="0"/>
<xsd:element name="epcList" type="epcis:EPCListType"/>
<xsd:element name="action" type="epcis:ActionType"/>
<xsd:element name="bizStep" type="epcis:BusinessStepIDType"
minOccurs="0"/>
<xsd:element name="disposition" type="epcis:DispositionIDType"
minOccurs="0"/>
<xsd:element name="readPoint" type="epcis:ReadPointType"
minOccurs="0"/>
<xsd:element name="bizLocation" type="epcis:BusinessLocationType"
minOccurs="0"/>
<xsd:element name="extension"
type="epcis:TransactionEventExtensionType" minOccurs="0"/>
<xsd:any namespace="##other" processContents="lax" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="EPCISDocumentExtensionType">
<xsd:sequence>
<xsd:any namespace="##local" processContents="lax"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:complexType>
<xsd:complexType name="EPCISHeaderExtensionType">
<xsd:sequence>
<xsd:any namespace="##local" processContents="lax"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:complexType>
<xsd:complexType name="EPCISBodyExtensionType">
<xsd:sequence>
<xsd:any namespace="##local" processContents="lax"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:complexType>
<xsd:complexType name="EPCISEventListExtensionType">
<xsd:sequence>
<xsd:any namespace="##local" processContents="lax"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:complexType>
<xsd:complexType name="EPCISEventExtensionType">
<xsd:sequence>
<xsd:any namespace="##local" processContents="lax"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:complexType>
<xsd:complexType name="ObjectEventExtensionType">
<xsd:sequence>
<xsd:any namespace="##local" processContents="lax"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:complexType>
<xsd:complexType name="AggregationEventExtensionType">
<xsd:sequence>
<xsd:any namespace="##local" processContents="lax"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:complexType>
<xsd:complexType name="QuantityEventExtensionType">
<xsd:sequence>
<xsd:any namespace="##local" processContents="lax"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:complexType>
<xsd:complexType name="TransactionEventExtensionType">
<xsd:sequence>
<xsd:any namespace="##local" processContents="lax"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"/>
</xsd:complexType>
</xsd:schema>

deanhiller

unread,
Oct 20, 2011, 3:44:47 PM10/20/11
to scalaxb
oh, and specifically, ObjectEventType is the one that is giving us
issues.

On Oct 20, 12:35 pm, eugene yokota <eed3s...@gmail.com> wrote:

eugene yokota

unread,
Oct 20, 2011, 10:48:25 PM10/20/11
to sca...@googlegroups.com
Ok. I collected all the dependent schemas, created a repro example,
and filed a case:
https://github.com/eed3si9n/scalaxb/issues/95

-eugene

eugene yokota

unread,
Oct 21, 2011, 2:03:06 AM10/21/11
to sca...@googlegroups.com
Hi Dean,

I fixed the issue, and published a 0.6.6-SNAPSHOT, and also updated
the sample code.

Before:

<ObjectType xsi:type="ObjectEventType"
xsi:type="epcis:ObjectEventType" xmlns:epcglobal="urn:epcglobal:xsd:1"


xmlns:epcis="urn:epcglobal:epcis:xsd:1"
xmlns:sbdh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"

xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><eventTime>2010-01-01</eventTime><eventTimeZoneOffset>Z</eventTimeZoneOffset><epcList></epcList><action>ADD</action><xsi:type>epcis:ObjectEventType</xsi:type></ObjectType>

After:

<ObjectType xsi:type="epcis:ObjectEventType"
xmlns="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"


xmlns:epcglobal="urn:epcglobal:xsd:1"
xmlns:epcis="urn:epcglobal:epcis:xsd:1"
xmlns:sbdh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"

xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><eventTime>2010-01-01</eventTime><eventTimeZoneOffset>Z</eventTimeZoneOffset><epcList></epcList><action>ADD</action></ObjectType>

Note we only have one xsi:type="epcis:ObjectEventType".
The issue was caused by xsi:type attribute was getting picked up by
xs:anyAttribute.

-eugene

deanhiller

unread,
Oct 21, 2011, 9:47:50 AM10/21/11
to scalaxb
wow, that was fast...thanks!!!
Dean

On Oct 21, 12:03 am, eugene yokota <eed3s...@gmail.com> wrote:
> Hi Dean,
>
Reply all
Reply to author
Forward
0 new messages