RE: Xmlbeans is able to retrieve extra attribute from xml ?

"Gillen, Paul" <[email protected]>
Newsgroups gmane.text.xml.xmlbeans.user
Message-ID <6A51CF4158562249906CB0F24DC99E444CD85DFD60@GATUCEXCH03ASV.nscorp.ad.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:[email protected]]
Sent: Wednesday, December 23, 2009 8:10 AM
To: [email protected]
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.