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