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

  • Home
  • SEARCH
  • 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 8442865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:57:26+00:00 2026-06-10T08:57:26+00:00

I’m having trouble creating an XML file from XSD using JAXB below is the

  • 0

I’m having trouble creating an XML file from XSD using JAXB below is the XSD file used to create it. (Note: Names have been edited due to confidentiality)

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://ibm.org/seleniumframework" xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="Test" type="sel:Test">
        <xs:complexType>
            <xs:choice minOccurs="1" maxOccurs="unbounded">
                <xs:element name="Option1" type="sel:Option1Type" xmlns:sel="http://ibm.org/seleniumframework"/>
                <xs:element name="Option2" type="sel:Option2Type" xmlns:sel="http://ibm.org/seleniumframework"/>
                <xs:element name="Option3" type="sel:ScreensType" xmlns:sel="http://ibm.org/seleniumframework"/>
            </xs:choice>
        </xs:complexType>
    </xs:element>

    <xs:complexType name="ScreensType">
        <xs:sequence>
            <xs:element type="sel:ScreenType" name="Screen" minOccurs="1" maxOccurs="unbounded" xmlns:sel="http://ibm.org/seleniumframework"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="ScreenType">
        <xs:sequence>
            <xs:element name="ScreenData" minOccurs="1" maxOccurs="unbounded" xmlns:sel="http://ibm.org/seleniumframework"/>
        </xs:sequence>
        <xs:attribute type="xs:string" name="name1" use="required" />
        <xs:attribute type="xs:string" name="name2" use="required" />
        <xs:attribute type="xs:string" name="name3" use="required" />
    </xs:complexType>

</xs:schema>

This is the code I am using to try and create the XML:

public void generateXml() throws JAXBException, IOException {

            Test test = new Test();
            ScreensType screens = new ScreensType();
            ScreenType screen = new ScreenType();
            screen.setName1("a");
            screen.setName2("b");
            screen.setName3("c");

            File f = new File("new.xml");
            JAXBContext context= JAXBContext.newInstance("com.q1labs.qa.xmlgenerator.model.generatedxmlclasses");
            Marshaller jaxbMarshaller = context.createMarshaller();
            jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

            jaxbMarshaller.marshal(test, f);
            jaxbMarshaller.marshal(test, System.out);

        }

This is the output

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
        <Test xmlns="http://ibm.org/seleniumframework"/>

How can I get the code to output the screens and the screen tag along with it’s properties, I’m not sure what I’m doing wrong.

  • 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-06-10T08:57:27+00:00Added an answer on June 10, 2026 at 8:57 am

    You create an instance of Test and ScreensType but never set any of their properties before marshalling them to XML. Below is the corrected code.

    public void generateXml() throws JAXBException, IOException {
        Test test = new Test();
        ScreensType screens = new ScreensType();
        test.getOption1OrOption2OrOption3().add(screens);
        ScreenType screen = new ScreenType();
        screen.setName1("a");
        screen.setName2("b");
        screen.setName3("c");
        screens.getScreen().add(screen);
    
        File f = new File("new.xml");
        JAXBContext context= JAXBContext.newInstance("com.q1labs.qa.xmlgenerator.model.generatedxmlclasses");
        Marshaller jaxbMarshaller = context.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    
        jaxbMarshaller.marshal(test, f);
        jaxbMarshaller.marshal(test, System.out);
    }
    

    Output

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Test xmlns="http://ibm.org/seleniumframework">
        <Option3>
            <Screen name1="a" name2="b" name3="c"/>
        </Option3>
    </Test>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
In my XML file chapters tag has more chapter tag.i need to display chapters
We're building an app, our first using Rails 3, and we're having to build
Does anyone know how can I replace this 2 symbol below from the string
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm parsing an XML file, the creators of it stuck in a bunch social
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.