thanks, but I'm not actually sure.  and I don't know where I'll received
extra attributes.

here a sample :

XSD

<?xml version="1.0" encoding="utf-8"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
   <device>
      <deviceType>urn:schemas-upnp-org:device:MediaServer:1</deviceType>
      <serviceList>
         <service>

<serviceType>urn:schemas-upnp-org:service:ConnectionManager:1</serviceType>

<serviceId>urn:upnp-org:serviceId:urn:schemas-upnp-org:service:ConnectionManager</serviceId>
            <SCPDURL>ConnectionManager.xml</SCPDURL>
            <controlURL>ConnectionManager/Control</controlURL>
            <eventSubURL>ConnectionManager/Event</eventSubURL>
         </service>
      </serviceList>
   </device>
</root>


XML received

<?xml version="1.0" encoding="utf-8"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
   <device>
      <deviceType>urn:schemas-upnp-org:device:MediaServer:1</deviceType>
      <serviceList>
         <service>

<serviceType>urn:schemas-upnp-org:service:ConnectionManager:1</serviceType>

<serviceId>urn:upnp-org:serviceId:urn:schemas-upnp-org:service:ConnectionManager</serviceId>
            <SCPDURL>ConnectionManager.xml</SCPDURL>
            <controlURL>ConnectionManager/Control</controlURL>
            <eventSubURL>ConnectionManager/Event</eventSubURL>
         </service>
      </serviceList>
      <dlna:X_DLNADOC xmlns:ns2="urn:schemas-upnp-org:device-1-0"
xmlns="">DMS-1.00</dlna:X_DLNADOC>
   </device>
</root>

if I do that :

RootDocument root = RootDocument.Factory.parse(new
File("./src/test/resources/RootDevice.xml"));
System.out.println(root.toString());

Exception in thread "main" org.apache.xmlbeans.XmlException: error:
Unexpected element: CDATA
    at
org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3486)
    at org.apache.xmlbeans.impl.store.Locale.parse(Locale.java:712)





2009/12/23 Gillen, Paul <paul.gil...@nscorp.com>

>  This seems to do what you’re asking.
>
>
>
> Assuming an XSD:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
> elementFormDefault="qualified" attributeFormDefault="unqualified">
>
>        <xs:element name="ATTRTEST">
>
>               <xs:complexType>
>
>                      <xs:sequence>
>
>                            <xs:element name="TESTELEM">
>
>                                   <xs:complexType>
>
>                                          <xs:attribute name="DEFATTR"
> type="xs:string"/>
>
>                                   </xs:complexType>
>
>                            </xs:element>
>
>                      </xs:sequence>
>
>               </xs:complexType>
>
>        </xs:element>
>
> </xs:schema>
>
> And XML:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <ATTRTEST xsi:noNamespaceSchemaLocation="../xsd/AttrTest.xsd" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance";>
>
>        <TESTELEM DEFATTR="defined" BOGUSATTR="bogus"/>
>
> </ATTRTEST>
>
> The following code:
>
> package test;
>
>
>
> import java.io.File;
>
>
>
> import javax.xml.namespace.QName;
>
>
>
> import org.apache.xmlbeans.impl.values.XmlObjectBase;
>
>
>
> import noNamespace.ATTRTESTDocument;
>
> import noNamespace.ATTRTESTDocument.ATTRTEST;
>
> import noNamespace.ATTRTESTDocument.ATTRTEST.TESTELEM;
>
>
>
> public class Atest
>
> {
>
>     public static void main(String[] args)
>
>     throws Exception
>
>     {
>
>         Atest o = new Atest();
>
>         o.go();
>
>     }
>
>
>
>     private void go()
>
>     throws Exception
>
>     {
>
>         ATTRTESTDocument    atd     = ATTRTESTDocument.Factory.parse(new
> File("xml/AttrTest.xml"));
>
>         ATTRTEST            at      = atd.getATTRTEST();
>
>         TESTELEM            te      = at.getTESTELEM();
>
>         System.out.println(te.getDEFATTR());
>
>         XmlObjectBase       ba      = (XmlObjectBase)te.selectAttribute(new
> QName("BOGUSATTR"));
>
>         System.out.println(ba.getStringValue());
>
>     }
>
> }
>
> Returns:
>
> defined
>
> bogus
>  ------------------------------
>
> Paul Gillen
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>  ------------------------------
>
> *From:* Sebastien Dionne [mailto:survivan...@gmail.com]
> *Sent:* Wednesday, December 23, 2009 8:10 AM
> *To:* user@xmlbeans.apache.org
> *Subject:* Xmlbeans is able to retrieve extra attribute from xml ?
>
>
>
> I have a simple question.
>
> I have a xsd standard (string..no complextype).
>
> I receive xml message that can contains extra attributes that are not in
> the xsd.
>
> With JAXB they are put into
>
>     /**
>      * Gets a map that contains attributes that aren't bound to any typed
> property on this class.
>      *
>      * <p>
>      * the map is keyed by the name of the attribute and
>      * the value is the string value of the attribute.
>      *
>      * the map returned by this method is live, and you can add new
> attribute
>      * by updating the map directly. Because of this design, there's no
> setter.
>      *
>      *
>      * @return
>      *     always non-null
>      */
>     public Map<QName, String> getOtherAttributes() {
>         return otherAttributes;
>     }
>
> but is it possible to do something similar with xmlbeans ?
>
> It a showstopper if I can't do that.
>
> thanks
>
>
> --
> -------------
> A+
>
> Sébastien.
>
> Vous pouvez me suivre sur Twitter / You can follow me on Twitter :
> http://twitter.com/survivant
>



-- 
-------------
A+

Sébastien.

Vous pouvez me suivre sur Twitter / You can follow me on Twitter :
http://twitter.com/survivant

Reply via email to