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 8850667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:57:19+00:00 2026-06-14T12:57:19+00:00

I would like to build some kind of object generation engine for my domain

  • 0

I would like to build some kind of object generation engine for my domain objects.
For example, lets assume, I’m working with graphs. The models are represented by xml and I should be able to load them and build a java representation at runtime.

Lets say, graph has vertices and edges
So it will look like this:

<graph>
   <vertex id="n1" color="red", thickness="2">
   <vertex id="n2">
   <edge end1="${n1}", end2="${n2}"/>
</graph>

For this I would like to get the objects that can be described by the following java classes:

class Graph {
     List<Vertex> vertexList
     List<Edge> edgeList
}

class Vertex {
   String id
    ... various properties ... 
}

class Edge {
   Vertex end1
   Vertex end2
}

Another requirement is to be able to define vertices in loop like this:

<graph>
  ...
    <for var = i, min = 1, max = 10, step = 1>
      <vertex id=$i.../> 
    </for>
  ... 
</graph>

I thought about using Apache Jelly but it seems to be a ‘dead’ project, JaxB doesn’t allow such a level of dynamic behavior AFAIK…

My question is – what framework can you recommend for implementing such a task?

If there is something that works like Apache Jelly but still maintained, it could be great also 🙂

Thanks a lot in advance

  • 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-14T12:57:20+00:00Added an answer on June 14, 2026 at 12:57 pm

    JAXB (JSR-222) implementations can easily handle references within a document using a combination of @XmlID and @XmlIDREF. I will demonstrate below with an example.

    JAVA MODEL

    Graph

    package forum13404583;
    
    import java.util.List;
    import javax.xml.bind.annotation.*;
    
    @XmlRootElement
    @XmlAccessorType(XmlAccessType.FIELD)
    class Graph {
    
        @XmlElement(name = "vertex")
        List<Vertex> vertexList;
    
        @XmlElement(name = "edge")
        List<Edge> edgeList;
    
    }
    

    Vertex

    In the Vertex class you need to use the @XmlID annotation to indicate that the id field is the id.

    package forum13404583;
    
    import javax.xml.bind.annotation.*;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    class Vertex {
    
        @XmlAttribute
        @XmlID
        String id;
    
        @XmlAttribute
        String color;
    
        @XmlAttribute
        Integer thickness;
    
    }
    

    Edge

    In the Edge class the @XmlIDREF annotation is used to indicate that the XML value contains a foreign key that references the real value.

    package forum13404583;
    
    import javax.xml.bind.annotation.*;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    class Edge {
    
        @XmlAttribute
        @XmlIDREF
        Vertex end1;
    
        @XmlAttribute
        @XmlIDREF
        Vertex end2;
    
    }
    

    DEMO CODE

    package forum13404583;
    
    import java.io.File;
    import javax.xml.bind.*;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            JAXBContext jc = JAXBContext.newInstance(Graph.class);
    
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            File xml = new File("src/forum13404583/input.xml");
            Graph graph = (Graph) unmarshaller.unmarshal(xml);
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(graph, System.out);
        }
    
    }
    

    INPUT (input.xml)/OUTPUT

    Below is the input to and output from running the demo code.

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <graph>
        <vertex id="n1" color="red" thickness="2"/>
        <vertex id="n2"/>
        <edge end1="n1" end2="n2"/>
    </graph>
    

    For More Information

    • http://blog.bdoughan.com/2010/10/jaxb-and-shared-references-xmlid-and.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to build some code which calls some code on loadup of
I would like to build some smaller scale but hightly customized documentation sites for
I'm using TFS 2008 and I would like to build some solutions in debug
I would like to build up a new IDocument object step by step using
I want to build some kind of audio processing unit. I would connect some
I would like to debug an embedded system containing gdb remotely using some kind
I would like to use some code written in python (it uses built in
I have built a Java application that has some dependencies (~10). I would like
I would like to build a php script that automatically generates a new id
I would like to build a cypher with python which decoding text by repeatedly

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.