You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by "Raif S. Naffah" <ra...@forge.com.au> on 2008/04/09 09:07:11 UTC

xsi:type related question (long)

hello all,

using version 2.3.0 i created the Java Binding classes for kml version
2.1 (http://code.google.com/apis/kml/schema/kml21.xsd).  parsing a kml
document similar to the following is ok:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
  <Document>
    <name>Document.kml</name>
    <open>1</open>
    <Style id="exampleStyleDocument">
      <LabelStyle>
        <color>ff0000cc</color>
      </LabelStyle>
    </Style>
    <Placemark>
      <name>Document Feature 1</name>
      <styleUrl>#exampleStyleDocument</styleUrl>
      <Point>
        <coordinates>-122.371,37.816,0</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>Document Feature 2</name>
      <styleUrl>#exampleStyleDocument</styleUrl>
      <Point>
        <coordinates>-122.370,37.817,0</coordinates>
      </Point>
    </Placemark>
  </Document>
</kml>

on the other hand, constructing a similar document and saving it
through the generated classes, with an XmlOptions instance set
as follows:

  ...
  setSaveNamespacesFirst();
  setSavePrettyPrint();
  setSavePrettyPrintIndent(2);
  setSaveAggressiveNamespaces();
  final Map<String,String> implicitNamespaces = new HashMap<String,String>();
  implicitNamespaces.put(
      "xsi", "http://www.w3.org/2001/XMLSchema-instance");
  setSaveImplicitNamespaces(implicitNamespaces);
  setUseDefaultNamespace();
  ...

end up with the following XML:

<kml xmlns="http://earth.google.com/kml/2.1">
  <Feature xmlns:ns="http://earth.google.com/kml/2.1" xsi:type="ns:DocumentType">
    <name>Document.kml</name>
    <open>true</open>
    <StyleSelector id="exampleStyleDocument" xsi:type="ns:StyleType">
      <LabelStyle>
        <color>FF0000CC</color>
      </LabelStyle>
    </StyleSelector>
    <Feature xsi:type="ns:PlacemarkType">
      <name>Document Feature 1</name>
      <styleUrl>#exampleStyleDocument</styleUrl>
      <Geometry xsi:type="ns:PointType">
        <coordinates>-122.371,37.817</coordinates>
      </Geometry>
    </Feature>
    <Feature xsi:type="ns:PlacemarkType">
      <name>Document Feature 2</name>
      <styleUrl>#exampleStyleDocument</styleUrl>
      <Geometry xsi:type="ns:PointType">
        <coordinates>-122.37,37.817</coordinates>
      </Geometry>
    </Feature>
  </Feature>
</kml>

what i'd like to get when saving the KmlDocument instance is something
close to the first version.

is this possible?  how?


TIA + cheers;
rsn

Re: type related question (long)

Posted by "Raif S. Naffah" <ra...@forge.com.au>.
hello Radu,

On Friday 25 April 2008 06:32:17 am Radu Preotiuc-Pietro wrote:
> You need to use the XmlObject.substitute(QName, SchemaType) method to
> let XMLBeans know you want to use substitution groups. Something
> along the lines of:
>
> newfeature.substitute(new QName("http://earth.google.com/kml/2.1",
> "Document"), DocumentType.type);

thank you muchly.  your solution gives me exactly what i want!


> > -----Original Message-----
> > From: Raif S. Naffah [mailto:raif@forge.com.au]
> > Sent: Wednesday, April 09, 2008 12:07 AM
> > To: user@xmlbeans.apache.org
> > Subject: xsi:type related question (long)
> >
> > hello all,
> >
> > using version 2.3.0 i created the Java Binding classes for kml
> > version 2.1 (http://code.google.com/apis/kml/schema/kml21.xsd).
> > parsing a kml document similar to the following is ok:
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <kml xmlns="http://earth.google.com/kml/2.1">
> >   <Document>
> >     <name>Document.kml</name>
> >     <open>1</open>
> >     <Style id="exampleStyleDocument">
> >       <LabelStyle>
> >         <color>ff0000cc</color>
> >       </LabelStyle>
> >     </Style>
> >     <Placemark>
> >       <name>Document Feature 1</name>
> >       <styleUrl>#exampleStyleDocument</styleUrl>
> >       <Point>
> >         <coordinates>-122.371,37.816,0</coordinates>
> >       </Point>
> >     </Placemark>
> >     <Placemark>
> >       <name>Document Feature 2</name>
> >       <styleUrl>#exampleStyleDocument</styleUrl>
> >       <Point>
> >         <coordinates>-122.370,37.817,0</coordinates>
> >       </Point>
> >     </Placemark>
> >   </Document>
> > </kml>
> >
> > on the other hand, constructing a similar document and saving
> > it through the generated classes, with an XmlOptions instance
> > set as follows:
> >
> >   ...
> >   setSaveNamespacesFirst();
> >   setSavePrettyPrint();
> >   setSavePrettyPrintIndent(2);
> >   setSaveAggressiveNamespaces();
> >   final Map<String,String> implicitNamespaces = new
> > HashMap<String,String>();
> >   implicitNamespaces.put(
> >       "xsi", "http://www.w3.org/2001/XMLSchema-instance");
> >   setSaveImplicitNamespaces(implicitNamespaces);
> >   setUseDefaultNamespace();
> >   ...
> >
> > end up with the following XML:
> >
> > <kml xmlns="http://earth.google.com/kml/2.1">
> >   <Feature xmlns:ns="http://earth.google.com/kml/2.1"
> > xsi:type="ns:DocumentType">
> >     <name>Document.kml</name>
> >     <open>true</open>
> >     <StyleSelector id="exampleStyleDocument"
> > xsi:type="ns:StyleType"> <LabelStyle>
> >         <color>FF0000CC</color>
> >       </LabelStyle>
> >     </StyleSelector>
> >     <Feature xsi:type="ns:PlacemarkType">
> >       <name>Document Feature 1</name>
> >       <styleUrl>#exampleStyleDocument</styleUrl>
> >       <Geometry xsi:type="ns:PointType">
> >         <coordinates>-122.371,37.817</coordinates>
> >       </Geometry>
> >     </Feature>
> >     <Feature xsi:type="ns:PlacemarkType">
> >       <name>Document Feature 2</name>
> >       <styleUrl>#exampleStyleDocument</styleUrl>
> >       <Geometry xsi:type="ns:PointType">
> >         <coordinates>-122.37,37.817</coordinates>
> >       </Geometry>
> >     </Feature>
> >   </Feature>
> > </kml>
> >
> > what i'd like to get when saving the KmlDocument instance is
> > something close to the first version.
> >
> > is this possible?  how?
> >
> >
> > TIA + cheers;
> > rsn
>
> Notice:  This email message, together with any attachments, may
> contain information  of  BEA Systems,  Inc.,  its subsidiaries  and 
> affiliated entities,  that may be confidential,  proprietary, 
> copyrighted  and/or legally privileged, and is intended solely for
> the use of the individual or entity named in this message. If you are
> not the intended recipient, and have received this message in error,
> please immediately return this by email and then delete it.



-- 
cheers;
rsn

RE: type related question (long)

Posted by Radu Preotiuc-Pietro <ra...@bea.com>.
You need to use the XmlObject.substitute(QName, SchemaType) method to
let XMLBeans know you want to use substitution groups. Something along
the lines of:

newfeature.substitute(new QName("http://earth.google.com/kml/2.1",
"Document"), DocumentType.type);

Radu

> -----Original Message-----
> From: Raif S. Naffah [mailto:raif@forge.com.au] 
> Sent: Wednesday, April 09, 2008 12:07 AM
> To: user@xmlbeans.apache.org
> Subject: xsi:type related question (long)
> 
> hello all,
> 
> using version 2.3.0 i created the Java Binding classes for kml version
> 2.1 (http://code.google.com/apis/kml/schema/kml21.xsd).  
> parsing a kml document similar to the following is ok:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <kml xmlns="http://earth.google.com/kml/2.1">
>   <Document>
>     <name>Document.kml</name>
>     <open>1</open>
>     <Style id="exampleStyleDocument">
>       <LabelStyle>
>         <color>ff0000cc</color>
>       </LabelStyle>
>     </Style>
>     <Placemark>
>       <name>Document Feature 1</name>
>       <styleUrl>#exampleStyleDocument</styleUrl>
>       <Point>
>         <coordinates>-122.371,37.816,0</coordinates>
>       </Point>
>     </Placemark>
>     <Placemark>
>       <name>Document Feature 2</name>
>       <styleUrl>#exampleStyleDocument</styleUrl>
>       <Point>
>         <coordinates>-122.370,37.817,0</coordinates>
>       </Point>
>     </Placemark>
>   </Document>
> </kml>
> 
> on the other hand, constructing a similar document and saving 
> it through the generated classes, with an XmlOptions instance 
> set as follows:
> 
>   ...
>   setSaveNamespacesFirst();
>   setSavePrettyPrint();
>   setSavePrettyPrintIndent(2);
>   setSaveAggressiveNamespaces();
>   final Map<String,String> implicitNamespaces = new 
> HashMap<String,String>();
>   implicitNamespaces.put(
>       "xsi", "http://www.w3.org/2001/XMLSchema-instance");
>   setSaveImplicitNamespaces(implicitNamespaces);
>   setUseDefaultNamespace();
>   ...
> 
> end up with the following XML:
> 
> <kml xmlns="http://earth.google.com/kml/2.1">
>   <Feature xmlns:ns="http://earth.google.com/kml/2.1" 
> xsi:type="ns:DocumentType">
>     <name>Document.kml</name>
>     <open>true</open>
>     <StyleSelector id="exampleStyleDocument" xsi:type="ns:StyleType">
>       <LabelStyle>
>         <color>FF0000CC</color>
>       </LabelStyle>
>     </StyleSelector>
>     <Feature xsi:type="ns:PlacemarkType">
>       <name>Document Feature 1</name>
>       <styleUrl>#exampleStyleDocument</styleUrl>
>       <Geometry xsi:type="ns:PointType">
>         <coordinates>-122.371,37.817</coordinates>
>       </Geometry>
>     </Feature>
>     <Feature xsi:type="ns:PlacemarkType">
>       <name>Document Feature 2</name>
>       <styleUrl>#exampleStyleDocument</styleUrl>
>       <Geometry xsi:type="ns:PointType">
>         <coordinates>-122.37,37.817</coordinates>
>       </Geometry>
>     </Feature>
>   </Feature>
> </kml>
> 
> what i'd like to get when saving the KmlDocument instance is 
> something close to the first version.
> 
> is this possible?  how?
> 
> 
> TIA + cheers;
> rsn
> 

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org