You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Brian Deep <bd...@cc-sw.com> on 2005/01/07 15:45:01 UTC

Help with validating a new instance

I am having problems validating an new instance of a document.  Has to be
something I am missing.  Can anyone help?

            // Set options for new instance
            XmlOptions opts = new XmlOptions();
            opts = opts.setDocumentType ( CustomerDocument.type );
            opts = opts.setDocumentSourceName("customer");
            ArrayList errorList = new ArrayList();
            opts = opts.setErrorListener(errorList);

            xmlRoot = XmlObject.Factory.newInstance( opts );

            if (! xmlRoot.validate( opts )) {
               ...
            
The error I get from validation is
"Expected element customer at the end of the content"
location = "<xml-fragment/>

I have added the customer element before validating but then get errors that
sub-elements are missing.  I put this code before validation

            XmlCursor cursor = xmlRoot.newCursor();
            cursor.toEndDoc();
            QName q = new QName (null, "customer");
            cursor.insertElement( q );

How far do I have to go before successful validation and how do I get rid of
<xml-fragment>?  Must be missing something...


Thanks,
-- Brian



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re[2]: Help with validating a new instance

Posted by Brian Deep <bd...@cc-sw.com>.
Ok, found my validation problem.  It was a problem with the schema where many
sub-elements were required in order to successfully validate.   I was doing it
correctly, but just not adding in all the required elements to validate.  Didn't write the
schema, so should have checked it first.

My last problem is I am still getting <xml-fragment> when I write an element to my
xml file.  For example, if I create a new instance and then add a customer

           CustomerDocument cDoc = CustomerDocument.Factory.newInstance();
           cDoc.addNewCustomer();

I get

<xml-fragment xmlns: ... >
              <customer/>
<xml-fragment/>


when what I want is

<customer xmlns: ... />


Anila, if your reply addresses this, I do not see where in the documentation.
All examples work from a parsed XML file, not a new instance.  Am I missing
something?

Thanks,
-- Brian


Friday, January 7, 2005, 9:58:21 AM, you wrote:
> I don't see where you are binding your XML document to your xmlRoot. See
> xmlbeans tutorial "Writing Code that Uses Generated Types".
>  
> Hope this helps!
>  
> Anila
> Brian Deep <bd...@cc-sw.com> wrote:
> I am having problems validating an new instance of a document. Has to be
> something I am missing. Can anyone help?

> // Set options for new instance
> XmlOptions opts = new XmlOptions();
> opts = opts.setDocumentType ( CustomerDocument.type );
> opts = opts.setDocumentSourceName("customer");
> ArrayList errorList = new ArrayList();
> opts = opts.setErrorListener(errorList);

> xmlRoot = XmlObject.Factory.newInstance( opts );

> if (! xmlRoot.validate( opts )) {
> ...

> The error I get from validation is
> "Expected element customer at the end of the content"
> location = "

> I have added the customer element before validating but then get errors that
> sub-elements are missing. I put this code before validation

> XmlCursor cursor = xmlRoot.newCursor();
> cursor.toEndDoc();
> QName q = new QName (null, "customer");
> cursor.insertElement( q );

> How far do I have to go before successful validation and how do I get rid of
> ? Must be missing something...


> Thanks,
> -- Brian



> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org







> Do you Yahoo!?
>  Yahoo! Mail - Find what you need with new enhanced search. Learn more.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: Help with validating a new instance

Posted by Girish Bhatia <bh...@gmail.com>.
I do not see where you have the document populated with xml data ?

Here is one example of validate that I am using. orderDoc is a valid
document that has been generated using an xml.

Collection errorList = new ArrayList();
        XmlOptions errorXO = new XmlOptions();
        errorXO.setErrorListener(errorList);
        if (!orderDoc.validate(errorXO)) {
            System.out.println("XSD Validation Errors : " + errorList.size());
            for (Iterator itr = errorList.iterator(); itr.hasNext(); ) {
                System.out.println("Error : " + itr.next());
            }
        }


On Fri, 7 Jan 2005 06:58:21 -0800 (PST), Anila Kardhashi
<a4...@yahoo.com> wrote:
> I don't see where you are binding your XML document to your xmlRoot. See
> xmlbeans tutorial "Writing Code that Uses Generated Types". 
>   
> Hope this helps! 
>   
> Anila
> Brian Deep <bd...@cc-sw.com> wrote: 
> I am having problems validating an new instance of a document. Has to be
> something I am missing. Can anyone help?
> 
> // Set options for new instance
> XmlOptions opts = new XmlOptions();
> opts = opts.setDocumentType ( CustomerDocument.type );
> opts = opts.setDocumentSourceName("customer");
> ArrayList errorList = new ArrayList();
> opts = opts.setErrorListener(errorList);
> 
> xmlRoot = XmlObject.Factory.newInstance( opts );
> 
> if (! xmlRoot.validate( opts )) {
> ...
> 
> The error I get from validation is
> "Expected element customer at the end of the content"
> location = "
> 
> I have added the customer element before validating but then get errors that
> sub-elements are missing. I put this code before validation
> 
> XmlCursor cursor = xmlRoot.newCursor();
> cursor.toEndDoc();
> QName q = new QName (null, "customer");
> cursor.insertElement( q );
> 
> How far do I have to go before successful validation and how do I get rid of
> ? Must be missing something...
> 
> 
> Thanks,
> -- Brian
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
> 
> 
> 
>  ________________________________
> Do you Yahoo!?
>  Yahoo! Mail - Find what you need with new enhanced search. Learn more. 
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


XMLBeans and memory leaks

Posted by Dima Gutzeit <di...@mailvision.net>.
Dear list members,

We have built application that relays on XMLBeans for XML parsing. The only thing we do with XMLBeans is parse XML input and reading the values during the application.

Now we are running stress tests and long run tests and seems that there is a memory leak inside the application. After investigating the issue with Borland Optimizeit (Profiler) it seems that leaks lead to the XMLBeans.

Has anyone expierenced memory leaks when using XMLBeans ? 

I am using version 1.0.3, which is the latest stable one.

I think I saw similar question on this list before, and now it became relevant to me as well.

Regards,

Dima Gutzeit.

Re: Help with validating a new instance

Posted by Anila Kardhashi <a4...@yahoo.com>.
I don't see where you are binding your XML document to your xmlRoot. See xmlbeans tutorial "Writing Code that Uses Generated Types".
 
Hope this helps!
 
Anila
Brian Deep <bd...@cc-sw.com> wrote:
I am having problems validating an new instance of a document. Has to be
something I am missing. Can anyone help?

// Set options for new instance
XmlOptions opts = new XmlOptions();
opts = opts.setDocumentType ( CustomerDocument.type );
opts = opts.setDocumentSourceName("customer");
ArrayList errorList = new ArrayList();
opts = opts.setErrorListener(errorList);

xmlRoot = XmlObject.Factory.newInstance( opts );

if (! xmlRoot.validate( opts )) {
...

The error I get from validation is
"Expected element customer at the end of the content"
location = "

I have added the customer element before validating but then get errors that
sub-elements are missing. I put this code before validation

XmlCursor cursor = xmlRoot.newCursor();
cursor.toEndDoc();
QName q = new QName (null, "customer");
cursor.insertElement( q );

How far do I have to go before successful validation and how do I get rid of
? Must be missing something...


Thanks,
-- Brian



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


		
---------------------------------
Do you Yahoo!?
 Yahoo! Mail - Find what you need with new enhanced search. Learn more.