Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 531977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:21:26+00:00 2026-05-13T09:21:26+00:00

In XmlBeans, I have a compiled schema and I create an instance through the

  • 0

In XmlBeans, I have a compiled schema and I create an instance through the

MyStuff stuff = MyStuff.Factory.newInstance() method.

But in a part of my application I need to treat MyStuff as a generic XmlObject and yet I want to create instances of it. Suppose that I want to do:

workWithObjectsAbstractly(stuff)

where workWithObjectsAbstractly is defined as:

public void workWithObjectsAbstractly(XmlObject o)
{
  .
  .
   SchemaType type = o.schemaType();
   XmlObject newInstance = type.???????   <--- is there such method?
  .
  .
  [Work with new instances as XmlObjects]
  . 
} 

Is there a way to do that?
I could inspect the schemaType through Particles and Properties and then create stuff with
XmlCursor, but it seems cumbersome. Can I avoid it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:21:26+00:00Added an answer on May 13, 2026 at 9:21 am

    I don’t think you can avoid this, org.apache.xmlbeans.impl.xsd2inst.XmlSampleUtil does this abstraction in order to create auto-generated, valid instances from a SchemaType.

    In this case, it uses

    XmlObject object = XmlObject.Factory.newInstance();
    XmlCursor cursor = object.newCursor();
    // Skip the document node
    cursor.toNextToken();
    // ... it then uses the cursor to add elements, attributes, etc
    

    Hope that helps a bit…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a schema which I use XmlBeans to umarshall to Java objects. I
I have a project which as part of the build process creates an XMLBeans
Apache XMLBeans can be used to generate Java classes and interfaces from XML Schema
I have a project which uses Apache Xmlbeans for databinding. Currently it is very
I have five WSDL's that share namespaces, but not all of them. I generate
I have been tasked with refactoring some components that used xmlbeans to now make
I have generated a client using Axis2 framework with XMLBeans as the data binding
What are you using for binding XML to Java? JAXB, Castor, and XMLBeans are
I have the following directory structure: schema1 schema1.xsd schema1.xsdconfig schema2 schema2.xsd schema2.xsdconfig schema3 schema3.xsd
I have to read xls file in java.I used poi-3.6 to read xls file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.