While I agree about the mess, XMLSpy generates the attached from the supplied XML. Compiling these with XMLBeans appears to let you address elements below the "command" level:
{ IqDocument doc = IqDocument.Factory.parse(new File("getProfile.xml")); Iq iq = doc.getIq(); Command command = iq.getCommand(); Iodata iodata = command.getIodata(); System.out.println("Iodata: "+iodata); } Paul -----Original Message----- From: Tim Watts [mailto:t...@cliftonfarm.org] Sent: Tuesday, November 09, 2010 1:57 PM To: user@xmlbeans.apache.org Subject: Re: While parsing with xmlBeans, sub branch is coming null This is quite a mess. I'm assuming you have to accept the input as is. Basically you've got 4 different XML vocabularies active in each xml instance doc: * The 1st one, which isn't in any namespace at all, containing only the {iq} element as well as ALL the attributes in ALL the elements (yes, ALL) * a 2nd containing only the {command} element * a 3rd containing the {iodata, out} elements * a 4th containing the {profiles, profile, actions, action} elements. Note that, according to the XML namespace spec, unqualified attributes are in NO namespace (not even the default) whereas unqualified elements are in the default namespace (assuming a default ns has been declared). [ sidenote: I doubt this effect was intended by design here. If it won't get you into trouble, do smack the author ever so gently at the back of the head. :-) ] Given that an .xsd can define a schema for only a single namespace I think you're going to have to create a separate .xsd for each of the above namespaces and set the targetNamespace to the appropriate xmlns. I'm not absolutely sure but I think for the "no namespace" stuff (i.e. <iq> and all the attributes) you should create an .xsd without a targetNamespace attr -- don't make it empty, leave it out entirely. Alternatively, you might be able to get away with creating a single "no namespace" .xsd and turning off namespace processing when parsing the xml docs. However, I'm not sure XmlBeans or Jaxb can function this way. On Tue, 2010-11-09 at 01:31 -0800, olamalam wrote: > Hello Tim, Thanks for your reply. > > I'm developing an integration project and I created that xsd file from the > xml file that our client sends us. I tried several different tools but none > of them creates a targetnamespace from the xml file that I attached. When I > try to assign a namespace manually I'm getting invalid xsd errors. > > But yes, you are right, there must be stg wrong with the xsd since I'm > having the same problem with Jaxb too. > > In the Jaxb forum, they advised me to remove xmlns="..." field from the tags > of xml. This is maybe why my xsd doesnt have a targetnamespace. Removing > xmlns fields from the each xml file received by my system programatically is > not a very practical solution. Therefore I guess I need to assign a > targetnamespace to my xsd. What should I put there? > > Thanks again, > ilker > > > Tim Watts-3 wrote: > > > > I could be wrong, but the odd thing I noticed was that the .xsd doesn't > > have a targetNamespace attr. I don't think simply declaring a namespace > > in the .xsd makes it part of the xml schema being defined. But maybe I'm > > misunderstanding your intent. It looks like you're trying to define a > > schema that spans multiple namespaces and I"m not sure that's supported > > in XML Schema. I'd love to learn otherwise. > > > > > > On Mon, 2010-11-08 at 08:27 -0800, olamalam wrote: > >> Hi to all, > >> > >> Actually, I'm not new to XmlBeans :) however I've faced with a problem > >> for > >> the first time and couldn't solve it. > >> > >> I"m using xmlBeans 2.4.0 and the xml file I'm trying to parse and it's > >> schema are attached. I created the .jar file by using "scomp" command > >> properly but when I parse the file, the first tag is returned with > >> correct > >> values at "id", "to", "from" and "type" fields but "command" object > >> returns > >> null. I also tried parsing it with JaxB but I got the same problem there > >> too. (I'm going to ask the same question to Jaxb forum) > >> > >> Can you see what I'm missing? > >> > >> http://old.nabble.com/file/p30162231/getProfile.xml getProfile.xml > >> http://old.nabble.com/file/p30162231/getProfile.xsd getProfile.xsd > > > > ________ > > It does not matter how slowly you go so long as you do not stop. > > -- Confucius > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: user-unsubscr...@xmlbeans.apache.org > > For additional commands, e-mail: user-h...@xmlbeans.apache.org > > > > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@xmlbeans.apache.org For additional commands, e-mail: user-h...@xmlbeans.apache.org
<?xml version="1.0" encoding="UTF-8"?> <!--W3C Schema generated by XMLSpy v2010 rel. 3 sp1 (http://www.altova.com)--> <xs:schema xmlns:n1="http://jabber.org/protocol/commands" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:import namespace="http://jabber.org/protocol/commands" schemaLocation="nabble1.xsd"/> <xs:element name="iq"> <xs:complexType> <xs:sequence> <xs:element ref="n1:command"/> </xs:sequence> <xs:attribute name="type" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="result"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="to" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="ad...@localhost/Smack"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="id" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="rPJNN-5"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="from" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="openlink.localhost"/> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:complexType> </xs:element> </xs:schema>
<?xml version="1.0" encoding="UTF-8"?> <!--W3C Schema generated by XMLSpy v2010 rel. 3 sp1 (http://www.altova.com)--> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:n3="urn:xmpp:tmp:io-data" xmlns:ns1="http://jabber.org/protocol/commands" targetNamespace="http://jabber.org/protocol/commands"> <xs:import namespace="urn:xmpp:tmp:io-data" schemaLocation="nabble2.xsd"/> <xs:element name="command"> <xs:complexType> <xs:sequence> <xs:element ref="n3:iodata"/> </xs:sequence> <xs:attribute name="status" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="completed"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="node" type="xs:anyURI" use="required"/> </xs:complexType> </xs:element> </xs:schema>
<?xml version="1.0" encoding="UTF-8"?> <!--W3C Schema generated by XMLSpy v2010 rel. 3 sp1 (http://www.altova.com)--> <xs:schema targetNamespace="urn:xmpp:tmp:io-data" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:n2="http://xmpp.org/protocol/openlink:01:00:00/profiles" xmlns:n3="urn:xmpp:tmp:io-data"> <xs:import namespace="http://xmpp.org/protocol/openlink:01:00:00/profiles" schemaLocation="nabble3.xsd"/> <xs:element name="out"> <xs:complexType> <xs:sequence> <xs:element ref="n2:profiles"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="iodata"> <xs:complexType> <xs:sequence> <xs:element ref="n3:out"/> </xs:sequence> <xs:attribute name="type" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="output"/> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:complexType> </xs:element> </xs:schema>
<?xml version="1.0" encoding="UTF-8"?> <!--W3C Schema generated by XMLSpy v2010 rel. 3 sp1 (http://www.altova.com)--> <xs:schema targetNamespace="http://xmpp.org/protocol/openlink:01:00:00/profiles" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:n2="http://xmpp.org/protocol/openlink:01:00:00/profiles"> <xs:element name="profiles"> <xs:complexType> <xs:sequence> <xs:element ref="n2:profile" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="profile"> <xs:complexType> <xs:sequence> <xs:element ref="n2:actions"/> </xs:sequence> <xs:attribute name="label" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="ITS AnyWhere user"/> <xs:enumeration value="ITS Mobile user"/> <xs:enumeration value="Netrix user"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="id" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="alan.trader_itsanywhere"/> <xs:enumeration value="alan.trader_itsmobile"/> <xs:enumeration value="alan.trader_netrix"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="default" type="xs:boolean"/> </xs:complexType> </xs:element> <xs:element name="actions"> <xs:complexType> <xs:sequence> <xs:element ref="n2:action" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="action"> <xs:complexType> <xs:attribute name="label" use="required" type="xs:string"/> <xs:attribute name="id" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="AnswerCall"/> <xs:enumeration value="ClearCall"/> <xs:enumeration value="ClearConnection"/> <xs:enumeration value="ConferenceCall"/> <xs:enumeration value="ConsultationCall"/> <xs:enumeration value="DivertCall"/> <xs:enumeration value="HoldCall"/> <xs:enumeration value="OutputCall"/> <xs:enumeration value="SendDigit"/> <xs:enumeration value="SingleStepTransfer"/> <xs:enumeration value="TransferCall"/> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:complexType> </xs:element> </xs:schema>
--------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@xmlbeans.apache.org For additional commands, e-mail: user-h...@xmlbeans.apache.org