Title: Message

I just raised a JIRA http://issues.apache.org/jira/browse/XMLBEANS-237 to track this as a feature request. But I have the same concerns that Radu does. At compile time both formats of the schema are perfectly valid (and I’ve heard people argue both ways on it) – so a warning doesn’t do you much good.

 

At runtime you could produce a warning but a) most people don’t have the XmlOption.setErrorListener() setup and so wouldn’t see the warning anyway and b) just trying to generate such a warning might have a serious impact on perf – as you now have to say not just “do I have something that matches this QName” but “do I have something that would look like this QName if I made certain assumptions about namespace prefixes etc.” There may be complicated things you could do by looking at the parent, or its parent or whatever but it certainly would have some negative effect on perf.

 

Anyway – I raised the JIRA. We can follow it up there.

 

Cheers,

 

Lawrence

 


From: Radu Preotiuc-Pietro
Sent: Friday, December 09, 2005 11:19 AM
To: [email protected]
Subject: RE: Attributes and NameSpaces

 

Well, XmlBeans doesn't really know when you meant to call something else and when you actually need are able to handle null (plus, adding any such code on the critical path for a 'get' would slow things down noticeably). But, what one can do when in doubt is call .validate() on the element that seems to be misbehaving and see if there are any validation errors, this may provide a clue...

 

Radu

-----Original Message-----
From: Samuel B. Quiring [mailto:[EMAIL PROTECTED]
Sent: Friday, December 09, 2005 9:41 AM
To: [email protected]
Subject: Re: Attributes and NameSpaces

Lawrence,

 

I ran into this exact problem when I started using xmlBeans and it was baffling and cost me hours of time before you sent a similiar explanation.

 

Isn't there some kind of creative check that xmlBeans could run to detect the possible existence of this problem and alert the user?

 

-Sam

----- Original Message -----

Sent: Friday, December 09, 2005 9:29 AM

Subject: RE: Attributes and NameSpaces

 

Hi Richard

 

I think you’re running into the infamous elementFormDefault=”qualified” | ”unqualified” issue.

 

If you don’t put an elementFormDefault attribute in the <schema> element of your schema the default is elementFormDefault=”unqualified”. This means that when you refer to non-global elements (such as your CustomerNumber, ValidCustomer … elements below) you _must_ refer to them _without_ a namespace. Global elements are unaffected by this setting – you must always refer to them with a namespace (if one was defined in the original schema).

 

On the other hand if you add the attribute elementFormDefault=”qualified” to the <schema> element then all elements (global and local) _must_ be referred to _with_ the namespace.

 

So you have 2 choices:

 

  1. Add elementFormDefault=”qualified” to your original schema and re-run scomp after which I think your code will work with the XML Instance doc you’ve provided.
  2. Change your XML instance doc so that instead of defining xmlns="http://infor.com/ResponseBatch" in your <ResponseBatch> element (which also affects the descendants of that element) you define just xmlns:tns="http://infor.com/ResponseBatch" and update your <ResponseBatch> to be <tns:ResponseBatch> (you can choose whatever prefix you like). Do _not_ add the same prefix to the children elements. Defining it this way will not affect the descendants of that element which will mean that they will get the “no-namespace” namespace – which is what you want if you don’t use elementFormDefault=”qualified”.

 

Personally I recommend option 1. But that’s just me – I’ve heard people argue it both ways.

 

Cheers,

 

Lawrence

 


From: Butterwood, Richard [mailto:[EMAIL PROTECTED]
Sent: Friday, December 09, 2005 8:40 AM
To: [email protected]
Subject: Attributes and NameSpaces

 

I can retrieve attributes using a XSD and XML without a name space, but with a namespace the following will not work.  I would appreciate any help.

 

XSD (ResponseBatch.xsd)

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

<xsd:schema targetNamespace="http://infor.com/ResponseBatch"

     xmlns="http://infor.com/ResponseBatch"

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

 

    <xsd:element name="ResponseBatch">

        <xsd:complexType>

            <xsd:sequence>

                <xsd:element name="CustomerNumber" type="xsd:string"/>

                <xsd:element name="ValidCustomer" type="xsd:string"/>

                <xsd:element name="CustomerName" type="xsd:string"/>

                <xsd:element name="ListPrice" type="xsd:int"/>

            </xsd:sequence>

            <xsd:attribute ref="ResponseID"/>

            <xsd:attribute ref="ConsumerKey"/>

            <xsd:attribute ref="Language"/>

            <xsd:attribute ref="DateTime"/>

            <xsd:attribute ref="SerialID"/>

        </xsd:complexType>

    </xsd:element>

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

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

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

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

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

</xsd:schema>

 

XML (ResponseBatch.xml)

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

<!-- Contains weather details of a location.-->

<ResponseBatch xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  ResponseID="ValidateCustomer" ConsumerKey="1234" Language="English" DateTime="today" SerialID="001" xmlns="http://infor.com/ResponseBatch">

    <CustomerNumber>C100</CustomerNumber>

    <ValidCustomer>Y</ValidCustomer>

    <CustomerName>Southeastern Industrial &amp; Supp</CustomerName>

    <ListPrice>3</ListPrice>

</ResponseBatch>

 

 

Java Test Code (ResponseBatch.java)

import com.infor.responseBatch.*;

 

 

// import noNamespace.*;

 

 

//          Illustrates how to use XMLBeans classes to get weather details from an

//          xml document in weatherInput.xml file.

 

public class ResponseBatch {

 

            public static void main(String args[]) {

 

                        try {

                                    System.out.println("At the start111");

                                    String filePath = "c:\\aa1\\ResponseBatch.xml";

                                    java.io.File inputXMLFile = new java.io.File(filePath);

 

                                    ResponseBatchDocument ResponseBatchDoc = ResponseBatchDocument.Factory

                                                            .parse(inputXMLFile);

                                    ResponseBatchDocument.ResponseBatch ResponseBatchElement = ResponseBatchDoc.getResponseBatch();

                                   

                                    System.out.println("ValidateCustomer details of Response ID "

                                                            + ResponseBatchElement.getResponseID()

                                                    + ", Consumer ID = " + ResponseBatchElement.getConsumerKey()

                                                            + ", Language = " + ResponseBatchElement.getLanguage()

                                                            + ", Date/Time = " + ResponseBatchElement.getDateTime()                                                         

                                                            + ", Serial ID = " + ResponseBatchElement.getSerialID());

 

                                    /* ResponseBatchDocument.ResponseBatch.Response ResponseElement = ResponseBatchElement.getResponse();

                                   

                                   

                                    System.out.println("Customer Number is "+ ResponseElement.getCustomerNumber());                              

                                    System.out.println("Customer Name is " + ResponseElement.getCustomerName());

                                    System.out.println("Valid Customer is "   + ResponseElement.getValidCustomer());

                                    System.out.println("List Price is "            + ResponseElement.getListPrice());

                                   

                                                                        */

                        } catch (Exception e) {

 

                                    e.printStackTrace();

                        }

 

            }

 

}          

 

Richard Butterwood | Senior Analyst/Programmer | Infor | office: 770-418-2000 X 1167 | cell: 678-492-3080 | fax: 770-418-2022 | [EMAIL PROTECTED]

 

SAVE THE DATE:
Inforum
Infor Customer Conference
April 9 – 12, 2006
Mandalay Bay Resort & Casino
Las Vegas

 

Reply via email to