Well, Rao, looks like you are a "victim" of the elementFormDefault. In XmlSchema, by default, when you declare a local element "Server" (like in your Schema) it goes into the "default namespace" rather than the "target namespace". You can do two things:
 
1. if you want to keep the Schema unmodified, then you need to change your document from <iw:Server .... > to <Server ....> and your XPath correspondingly
2. if you want to keep the document and the XPath the same, then you need to change your Schema to either make "Server" a global element and then use <element ref="tns:Server"> instead of <element name="Server".....> OR put elementFormDefault="qualified", either on the declaration of the element or on the top-level <schema>
 
In general, validating the document upon loading (via iwf.validate()) is a good idea in case you think something is amiss. Validation is not done by default by XmlBeans but it is easy to do it, and has the benefit of providing detailed error messages with line and column numbers to help you figure out what's wrong.
 
Radu


From: Rama Mohan Rao Peruri [mailto:[EMAIL PROTECTED]
Sent: Wednesday, July 26, 2006 9:15 PM
To: [email protected]
Subject: XPath returns XMLObject instead of the actual Type

Hi,

 

I am new to XmlBeans.  I like what I see so far.  I am having a problem getting XmlBeans to return the actual type (ServerType) for my XPath query.   What I get is XmlObject.  Obviously, I am making some mistake.  But what is it?  Please help J J

 

1. My Code:

 

String queryExpression = "declare namespace iw='http://www.rao.com/iwf/xml-config';"

                                  + "./iw:iwf/iw:Server";

 

XmlOptions xopt = new XmlOptions();

xopt.setSaveOuter();

xopt.setSaveUseOpenFrag();

xopt.setUseDefaultNamespace();

XmlObject[] xo = idoc.selectPath(queryExpression, xopt);

 

System.out.println(xo.getClass().getName());

System.out.println(xo[0].toString());

 

2.  Output:

 

When querying for the IW:IWF elements, the output is

 

[Lcom.rao.iwf.xmlConfig.IwfType;

<xml-fragment xsi:schemaLocation="http://www.dbs.com/iwf/xml-config IwfConfigXml.xsd" xmlns:iw="http://www.dbs.com/iwf/xml-config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude">

…. More lines deleted …

 

 

When querying for the IW:IWF / IW:Server elements, the output is

 

[Lorg.apache.xmlbeans.XmlObject;

<xml-fragment id="datadb" provider="oracle-db" host="localhost" port="1521" instance="ora92" user-id="swpro" password="swpro" xmlns:iw="http://www.dbs.com/iwf/xml-config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude"/>

 

Notice that the ClassName is XmlObject and not ServerType (which I expect).

 

3.  XSD

 

<?xml version = "1.0" encoding = "UTF-8"?>

<xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema"

            targetNamespace="http://www.rao.com/iwf/xml-config"

            xmlns:iwf="http://www.rao.com/iwf/xml-config">

   

    <xsd:element name="iwf" type="iwf:IwfType" />

 

      <xsd:complexType name="IwfType">

            <xsd:sequence>

                  <xsd:element name="Server" type="iwf:ServerType" minOccurs="0" maxOccurs="unbounded"/>

            </xsd:sequence>

      </xsd:complexType>

 

      <xsd:complexType name="ServerType">

          <xsd:attribute name="id"       type="xsd:string" />

          <xsd:attribute name="provider" type="xsd:string" />

    </xsd:complexType>

</xsd:schema>

 

4.  XML

 

<?xml version="1.0" encoding="UTF-8"?>

 

<iw:iwf xmlns:iw="http://www.dbs.com/iwf/xml-config"

     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

     xmlns:xi="http://www.w3.org/2001/XInclude"    

     xsi:schemaLocation="http://www.dbs.com/iwf/xml-config IwfConfigXml.xsd">

 

    <!-- SERVERS -->

    <iw:Server id="datadb"  provider="oracle-db"/>

</iw:iwf>

 

 

Best Regards

Rao (Peruri Rama Mohan Rao)

CONFIDENTIAL NOTE: The information contained in this email is intended only for the use of the individual or entity named above and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this message in error, please immediately notify the sender and delete the mail. Thank you.

_______________________________________________________________________
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.

Reply via email to