JAXB and inheritance. Converting xml to java object

I have a schema "FreeStyle.xsd" i used JAXB to generate POJO's . I get around 15 classes. I have a config.xml which is compliant to this schema . Now i want to write a java program which takes the config.xml and converts it into a java object . Please anybody help me with this . Thanks in advance
Freestyle.xsd
<?xml version="1.0" encoding="windows-1252"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="FreeStyleProject" type="hudson.model.FreeStyleProject"/>
<xsd:complexType name="hudson.model.FreeStyleProject">
  <xsd:complexContent>
   <xsd:extension base="hudson.model.Project">
    <xsd:sequence/>
   </xsd:extension>
  </xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="hudson.model.Project">
  <xsd:complexContent>
   <xsd:extension base="hudson.model.BaseBuildableProject">
    <xsd:sequence/>
   </xsd:extension>
  </xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="hudson.model.BaseBuildableProject">
  <xsd:complexContent>
   <xsd:extension base="hudson.model.AbstractProject">
    <xsd:sequence/>
   </xsd:extension>
  </xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="hudson.model.AbstractProject">
  <xsd:complexContent>
   <xsd:extension base="hudson.model.Job">
    <xsd:sequence>
     <xsd:element name="concurrentBuild" type="xsd:boolean"/>
     <xsd:element name="downstreamProject" type="hudson.model.AbstractProject"
                  minOccurs="0" maxOccurs="unbounded"/>
     <xsd:element name="scm" type="hudson.scm.SCM" minOccurs="0"/>
     <xsd:element name="upstreamProject" type="hudson.model.AbstractProject"
                  minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
   </xsd:extension>
  </xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="hudson.scm.SCM">
  <xsd:sequence>
   <xsd:element name="browser" type="hudson.scm.RepositoryBrowser"
                minOccurs="0"/>
   <xsd:element name="type" type="xsd:string" minOccurs="0"/>
  </xsd:sequence>
</xsd:complexType>
<xsd:complexType name="hudson.scm.RepositoryBrowser">
  <xsd:sequence/>
</xsd:complexType>
<xsd:complexType name="hudson.model.Job">
  <xsd:complexContent>
   <xsd:extension base="hudson.model.AbstractItem">
    <xsd:sequence>
     <xsd:element name="buildable" type="xsd:boolean"/>
     <xsd:element name="build" type="hudson.model.Run" minOccurs="0"
                  maxOccurs="unbounded"/>
     <xsd:element name="cascadingChildrenName" type="xsd:string" minOccurs="0"
                  maxOccurs="unbounded"/>
     <xsd:element name="color" type="hudson.model.BallColor" minOccurs="0"/>
     <xsd:element name="firstBuild" type="hudson.model.Run" minOccurs="0"/>
     <xsd:element name="healthReport" type="hudson.model.HealthReport"
                  minOccurs="0" maxOccurs="unbounded"/>
     <xsd:element name="inQueue" type="xsd:boolean"/>
     <xsd:element name="keepDependencies" type="xsd:boolean"/>
     <xsd:element name="lastBuild" type="hudson.model.Run" minOccurs="0"/>
     <xsd:element name="lastCompletedBuild" type="hudson.model.Run"
                  minOccurs="0"/>
     <xsd:element name="lastFailedBuild" type="hudson.model.Run" minOccurs="0"/>
     <xsd:element name="lastStableBuild" type="hudson.model.Run" minOccurs="0"/>
     <xsd:element name="lastSuccessfulBuild" type="hudson.model.Run"
                  minOccurs="0"/>
     <xsd:element name="lastUnstableBuild" type="hudson.model.Run"
                  minOccurs="0"/>
     <xsd:element name="lastUnsuccessfulBuild" type="hudson.model.Run"
                  minOccurs="0"/>
     <xsd:element name="nextBuildNumber" type="xsd:int"/>
     <xsd:element name="property" type="hudson.model.JobProperty" minOccurs="0"
                  maxOccurs="unbounded"/>
     <xsd:element name="queueItem" type="hudson.model.Queue-Item"
                  minOccurs="0"/>
    </xsd:sequence>
   </xsd:extension>
  </xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="hudson.model.Queue-Item">
  <xsd:complexContent>
   <xsd:extension base="hudson.model.Actionable">
    <xsd:sequence>
     <xsd:element name="blocked" type="xsd:boolean"/>
     <xsd:element name="buildable" type="xsd:boolean"/>
     <xsd:element name="id" type="xsd:int">
      <xsd:annotation>
       <xsd:documentation>VM-wide unique ID that tracks the {@link Task} as it
                          moves through different stages in the queue (each
                          represented by different subtypes of {@link Item}.</xsd:documentation>
      </xsd:annotation>
     </xsd:element>
     <xsd:element name="inQueueSince" type="xsd:long"/>
     <xsd:element name="params" type="xsd:string" minOccurs="0"/>
     <xsd:element name="stuck" type="xsd:boolean"/>
     <xsd:element name="task" type="xsd:anyType" minOccurs="0">
      <xsd:annotation>
       <xsd:documentation>Project to be built.</xsd:documentation>
      </xsd:annotation>
     </xsd:element>
     <xsd:element name="why" type="xsd:string" minOccurs="0"/>
    </xsd:sequence>
   </xsd:extension>
  </xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="hudson.model.Actionable">
  <xsd:sequence>
   <xsd:element name="action" type="xsd:anyType" minOccurs="0"
                maxOccurs="unbounded"/>
  </xsd:sequence>
</xsd:complexType>
<xsd:complexType name="hudson.model.JobProperty">
  <xsd:sequence/>
</xsd:complexType>
<xsd:complexType name="hudson.model.HealthReport">
  <xsd:sequence>
   <xsd:element name="description" type="xsd:string" minOccurs="0"/>
   <xsd:element name="iconUrl" type="xsd:string" minOccurs="0"/>
   <xsd:element name="score" type="xsd:int"/>
  </xsd:sequence>
</xsd:complexType>
<xsd:complexType name="hudson.model.Run">
  <xsd:complexContent>
   <xsd:extension base="hudson.model.Actionable">
    <xsd:sequence>
     <xsd:element name="artifact" type="hudson.model.Run-Artifact" minOccurs="0"
                  maxOccurs="unbounded"/>
     <xsd:element name="building" type="xsd:boolean"/>
     <xsd:element name="description" type="xsd:string" minOccurs="0"/>
     <xsd:element name="duration" type="xsd:long"/>
     <xsd:element name="fullDisplayName" type="xsd:string" minOccurs="0"/>
     <xsd:element name="id" type="xsd:string" minOccurs="0"/>
     <xsd:element name="keepLog" type="xsd:boolean"/>
     <xsd:element name="number" type="xsd:int"/>
     <xsd:element name="result" type="xsd:anyType" minOccurs="0"/>
     <xsd:element name="timestamp" type="xsd:long" minOccurs="0"/>
     <xsd:element name="url" type="xsd:string" minOccurs="0"/>
    </xsd:sequence>
   </xsd:extension>
  </xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="hudson.model.Run-Artifact">
  <xsd:sequence>
   <xsd:element name="displayPath" type="xsd:string" minOccurs="0"/>
   <xsd:element name="fileName" type="xsd:string" minOccurs="0"/>
   <xsd:element name="relativePath" type="xsd:string" minOccurs="0">
    <xsd:annotation>
     <xsd:documentation>Relative path name from {@link Run#getArtifactsDir()}</xsd:documentation>
    </xsd:annotation>
   </xsd:element>
  </xsd:sequence>
</xsd:complexType>
<xsd:complexType name="hudson.model.AbstractItem">
  <xsd:complexContent>
   <xsd:extension base="hudson.model.Actionable">
    <xsd:sequence>
     <xsd:element name="description" type="xsd:string" minOccurs="0"/>
     <xsd:element name="displayName" type="xsd:string" minOccurs="0"/>
     <xsd:element name="name" type="xsd:string" minOccurs="0"/>
     <xsd:element name="url" type="xsd:string" minOccurs="0"/>
    </xsd:sequence>
   </xsd:extension>
  </xsd:complexContent>
</xsd:complexType>
<xsd:simpleType name="hudson.model.BallColor">
  <xsd:restriction base="xsd:string">
   <xsd:enumeration value="red"/>
   <xsd:enumeration value="red_anime"/>
   <xsd:enumeration value="yellow"/>
   <xsd:enumeration value="yellow_anime"/>
   <xsd:enumeration value="green"/>
   <xsd:enumeration value="green_anime"/>
   <xsd:enumeration value="blue"/>
   <xsd:enumeration value="blue_anime"/>
   <xsd:enumeration value="grey"/>
   <xsd:enumeration value="grey_anime"/>
   <xsd:enumeration value="disabled"/>
   <xsd:enumeration value="disabled_anime"/>
   <xsd:enumeration value="aborted"/>
   <xsd:enumeration value="aborted_anime"/>
  </xsd:restriction>
</xsd:simpleType>
</xsd:schema>
Config.xml
<?xml version='1.0' encoding='UTF-8'?>
<project>
  <actions/>
  <description>Sample job ..</description>
  <project-properties class="java.util.concurrent.ConcurrentHashMap">
    <entry>
      <string>hudson-plugins-disk_usage-DiskUsageProperty</string>
      <base-property>
        <originalValue class="hudson.plugins.disk_usage.DiskUsageProperty"/>
        <propertyOverridden>false</propertyOverridden>
      </base-property>
    </entry>
    <entry>
      <string>jdk</string>
      <string-property>
        <originalValue class="string">(Inherit From Job)</originalValue>
        <propertyOverridden>false</propertyOverridden>
      </string-property>
    </entry>
    <entry>
      <string>scm</string>
      <scm-property>
        <originalValue class="hudson.scm.NullSCM"/>
        <propertyOverridden>false</propertyOverridden>
      </scm-property>
    </entry>
  </project-properties>
  <keepDependencies>false</keepDependencies>
  <creationTime>1402648240275</creationTime>
  <properties/>
  <cascadingChildrenNames class="java.util.concurrent.CopyOnWriteArraySet"/>
  <cascading-job-properties class="java.util.concurrent.CopyOnWriteArraySet">
    <string>hudson-plugins-batch_task-BatchTaskProperty</string>
    <string>hudson-plugins-disk_usage-DiskUsageProperty</string>
    <string>hudson-plugins-jira-JiraProjectProperty</string>
    <string>org-hudsonci-plugins-snapshotmonitor-WatchedDependenciesProperty</string>
    <string>hudson-plugins-promoted_builds-JobPropertyImpl</string>
  </cascading-job-properties>
  <scm class="hudson.scm.NullSCM"/>
  <canRoam>false</canRoam>
  <disabled>false</disabled>
  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
  <concurrentBuild>false</concurrentBuild>
  <cleanWorkspaceRequired>false</cleanWorkspaceRequired>
</project>
the file generated by JAXB are
com\model\HudsonModelAbstractItem.java
com\model\HudsonModelAbstractProject.java
com\model\HudsonModelActionable.java
com\model\HudsonModelBallColor.java
com\model\HudsonModelBaseBuildableProject.java
com\model\HudsonModelFreeStyleProject.java
com\model\HudsonModelHealthReport.java
com\model\HudsonModelJob.java
com\model\HudsonModelJobProperty.java
com\model\HudsonModelProject.java
com\model\HudsonModelQueueItem.java
com\model\HudsonModelRun.java
com\model\HudsonModelRunArtifact.java
com\model\HudsonScmRepositoryBrowser.java
com\model\HudsonScmSCM.java
com\model\ObjectFactory.java
Any help will be appreciated .
Thanks in advance

Unmarshal the config.xml to Java object.
Basic JAXB Examples - The Java EE 5 Tutorial

Similar Messages

  • Converting XML to Java Objects...possible?

    Hi, Am a newbie to JAXB. As far as I read, JAXB has facility to convert "XSD" (not XML) to Java "classes" (not objects). This can be done using xjc compiler. Can XML files (i.e. ones with data) be converted to Java objects (retaining the data from XML files)? If yes, please throw some light on how it can be done. If no, then is there some java technology to do such a thing?
    Thanks.

    http://xmlbeans.apache.org/

  • How to convert XML to Java Object

    Hello:
    I would like to convert an XML doucment into an object, but I having alot of trouble doing this.
    here is the document:
    <?xml version="1.0" encoding="UTF-8"?>
    <Marketing_Programs>
    <Marketing_Program>
    <rateCode type="String">A</rateCode>
    <plan type="String">AAA/CAA</plan>
    <flatRate type="double">0.0</flatRate>
    <discountRate type="double">10.0</discountRate>
    </Marketing_Program>
    <Marketing_Program>
    <rateCode type="String">B</rateCode>
    <plan type="String">Business Rate</plan>
    <flatRate type="double">0.0</flatRate>
    <discountRate type="double">5.0</discountRate>
    </Marketing_Program>
    </Marketing_Programs>
    A Marketing_Program class exists and so I want to create multiple Marketing_Program objects and store it in hashmap. I'm pretty much stuck on XML to object conversion due to lack of knowledge on converting string to the appropriate datatype.
    Any help would be greatly appreciated!
    Thanks in advance!
    Peter

    using jaxb, castor, jox...
    [email protected]

  • Convert MBox into XML into Java Objects

    Hello all,
    this is a general question, i dont know weather there is such libs or not.
    However, please tell me what you know.
    i want to program a java application for searching purpose in Mbox.
    i thought its possible and easier to try to convert the emails from the MBox into XML files, and from these create java objects when i need or even convert the XML into html for viewing.
    Any suggestions are welcome.
    Also antoher solutions are greate.
    thanks in advance!
    Sako.

    I don't know what this MBox you speak of is - I assume it's not the thing I use to hook upa guitar to GarageBand. Maybe you mean it as a generic term for mailbox? The easiest solution (to my mind) would be to use a Java API provided by whatever MBox is. If there is no such thing, then if you get XML-formatted version of the messages I suppose writing code to parse the XML into Java Objects would be a good option if you wanted to do further manipulation of them, but if all you want to do is display them as HTML in a browser then just use XSLT to transform them.
    Good Luck
    Lee

  • XML to java object AND Performance

    Hi,
    I read some article about marshalling a XML file to Java Object (like Castor, XML Beans projects...)
    To resume: I would like to marshal a XML doc (from XML to Java object. Later I would like to put these objects on a SGBD...). Unfortenaly I suppose that approach is to expensive on term of performance? Supposing that my xml doc contain 100 data's occurances, XML bean woulkd create 100 objects corresponding. My problem is that I don't want that the all 100 objects live in the same time on memory. For example, my code will read sequential, the xml occurances (like a Sax parser), create 10 datas objects (standby), put these in the data base, and destroy these objects before...iteratively create the next 10 objects...
    It is possible ? Can anybody help me?
    Thank

    On the article: Java Architecture for XML Binding (JAXB)
    (http://java.sun.com/developer/technicalArticles/WebServices/jaxb/)
    I found maybe a response?
    "...in other words, you can do a SAX parse of a document and then pass the events to JAXB for unmarshalling. "
    But somebody could help me to write the code to do that?

  • How to parse XML to Java object... please help really stuck

    Thank you for reading this email...
    If I have a **DTD** like:
    <!ELEMENT person (name, age)>
    <!ATTLIST person
         id ID #REQUIRED
    >
    <!ELEMENT name ((family, given) | (given, family))>
    <!ELEMENT age (#PCDATA)>
    <!ELEMENT family (#PCDATA)>
    <!ELEMENT given (#PCDATA)>
    the **XML** like:
    <person id="a1">
    <name>
         <family> Yoshi </family>
         <given> Samurai </given>
    </name>
    <age> 21 </age>
    </person>
    **** Could you help me to write a simple parser to parse my DTD and XML to Java object, and how can I use those objects... sorry if the problem is too basic, I am a beginner and very stuck... I am very confuse with SAXParserFactory, SAXParser, ParserAdapter and DOM has its own Factory and Parser, so confuse...
    Thank you for your help, Yo

    Hi, Yo,
    Thank you very much for your help. And I Wish you are there...I'm. And I plan to stay - It's sunny and warm here in Honolulu and the waves are up :)
    A bit more question for dear people:
    In the notes, it's mainly focus on JAXB,
    1. Is that mean JAXB is most popular parser for
    parsing XML into Java object? With me, definitely. There are essentially 3 technologies that allow you to parse XML documents:
    1) "Callbacks" (e.g. SAX in JAXP): You write a class that overrides 3 methods that will be called i) whenever the parser encounters a start tag, ii) an end tag, or iii) PCDATA. Drawback: You have to figure out where the heck in the document hierarchy you are when such a callback happens, because the same method is called on EACH start tag and similarly for the end tag and the PCDATA. You have to create the objects and put them into your own data structure - it's very tedious, but you have complete control. (Well, more or less.)
    2) "Tree" (e.g. DOM in JAXP, or it's better cousin JDOM): You call a parser that in one swoop creates an entire hierarchy that corresponds to the XML document. You don't get called on each tag as with SAX, you just get the root of the resulting tree. Drawback: All the nodes in the tree have the same type! You probably want to know which tags are in the document, don't you? Well, you'll have to traverse the tree and ask each node: What tag do you represent? And what are your attributes? (You get only strings in response even though your attributes often represent numbers.) Unless you want to display the tree - that's a nice application, you can do it as a tree model for JTree -, or otherwise don't care about the individual tags, DOM is not of much help, because you have to keep track where in the tree you are while you traverse it.
    3) Enter JAXB (or Castor, or ...): You give it a grammar of the XML documents you want to parse, or "unmarshall" as the fashion dictates to call it. (Actually the name isn't that bad, because "parsing" focuses on the input text while "unmarshalling" focuses on the objects you get, even though I'd reason that it should be marshalling that converts into objects and unmarshalling that converts objects to something else, and not vice versa but that's just my opinion.) The JAXB compiler creates a bunch of source files each with one (or now more) class(es) (and now interfaces) that correspond to the elements/tags of your grammar. (Now "compiler" is a true jevel of a misnomer, try to explain to students that after they run the "compiler", they still need to compile the sources the "compiler" generated with the real Java compiler!). Ok, you've got these sources compiled. Now you call one single method, unmarshall() and as a result you get the root node of the hierarchy that corresponds to the XML document. Sounds like DOM, but it's much better - the objects in the resulting tree don't have all the same type, but their type depends on the tag they represent. E.g if there is the tag <ball-game> then there will be an object of type myPackage.BallGame in your data structure. It gets better, if there is <score> inside <ball-game> and you have an object ballGame (of type BallGame) that you can simply call ballGame.getScore() and you get an object of type myPackage.Score. In other words, the child tags become properties of the parent object. Even better, the attributes become properties, too, so as far as your program is concerned there is no difference whether the property value was originally a tag or an attribute. On top of that, you can tell in your schema that the property has an int value - or another primitive type (that's like that in 1.0, in the early release you'll have to do it in the additional xjs file). So this is a very natural way to explore the data structure of the XML document. Of course there are drawbacks, but they are minor: daunting complexity and, as a consequence, very steep learning curve, documentation that leaves much to reader's phantasy - read trial and error - (the user's guide is too simplicistic and the examples too primitive, e.g. they don't even tell you how to make a schema where a tag has only attributes) and reference manual that has ~200 pages full of technicalities and you have to look with magnifying glas for the really usefull stuff, huge number of generated classes, some of which you may not need at all (and in 1.0 the number has doubled because each class has an accompanying interface), etc., etc. But overall, all that pales compared to the drastically improved efficiency of the programmer's efforts, i.e. your time. The time you'll spend learning the intricacies is well spent, you'll learn it once and then it will shorten your programming time all the time you use it. It's like C and Java, Java is order of magnitude more complex, but you'd probably never be sorry you gave up C.
    Of course the above essay leaves out lots and lots of detail, but I think that it touches the most important points.
    A word about JAXB 1.0 vs. Early Release (EA) version. If you have time, definitively learn 1.0, they are quite different and the main advantage is that the schema combines all the info that you had to formulate in the DTD and in the xjs file when using the EA version. I suggested EA was because you had a DTD already, but in retrospect, you better start from scratch with 1.0. The concepts in 1.0 are here to stay and once your surmounted the learning curve, you'll be glad that you don't have to switch concepts.
    When parser job is done,
    what kind of Java Object we will get? (String,
    InputStream or ...)See above, typically it's an object whose type is defined as a class (and interface in 1.0) within the sources that JABX generates. Or it can be a String or one of the primitive types - you tell the "compiler" in the schema (xjs file in EA) what you want!
    2. If we want to use JAXB, we have to contain a
    XJS-file? Something like:In EA, yes. In 1.0 no - it's all in the schema.
    I am very new to XML, is there any simpler way to get
    around them? It has already take me 4 days to find a
    simple parser which give it XML and DTD, then return
    to me Java objects ... I mean if that kind of parser
    exists....It'll take you probably magnitude longer that that to get really familiar with JAXB, but believe me it's worth it. You'll save countless days if not weeks once you'll start developing serious software with it. How long did it take you to learn Java and it's main APIs? You'll either invest the time learning how to use the software others have written, or you invest it writing it yourself. I'll take the former any time. But it's only my opinion...
    Jan

  • Converting XML to Java in STB

    I am trying to convert xml to java. Looking for simple and light way to covert xml to java in STB.

    Heh - all the tags in your question got stripped out by the forum-to-email bridge :-)
    Anyway, basically you just parse the XML data. You can use some
    kind of library if you like, but it turns out that parsing an XML response
    that's consistently formatted the same way isn't all that hard to do directly.
    In the HD cookbook project, we have a sample xlet that does just this, reading
    weather data from some public web service out there (I forget which - maybe
    Yahoo's?) The xlet could be converted to work on MHP or OCAP without
    much work. This demo is in xlets/demos/weatherWidget, and the project
    is at http://hdcookbook.com, click on the sumo wrestler. It's in the source-code repository,
    but over on the right one of the links will let you browse individual files, which should
    get you pretty quickly to the XML parser in this demo.
    By the way, if you have a choice between JSON and XML in this environment, I'd
    personally go with JSON. It's simpler to parse and faster - indeed, see
    com.hdcookbook.grin.util.JsonIO in the cookbook repository. Of course, if you're
    interacting with a server under your control and you want maximum performance, you
    can use a more efficient binary format, too.
    Cheers,
    Bill

  • Read, Modify and Apply Report XML using Java Script

    Hi Guys,
    Is there any way that we can Pragmatically Read, Modify and Apply Report XML using Java Script or some other way.
    Thanks
    Kaushik
    Edited by: Kaushik K on Jun 20, 2012 8:36 PM

    Requirement ::
    Users should be able to add Column to the Report Dynamically at Runtime.
    (There are around 1000+ Users, Answers Approach is not acceptable)
    So we are planning to provide a Multi Select / Shuttle Box Option for Users to add Columns dynamically. (Only for Table View)
    What we planned to DO ::
    Create a Presentation Variable Prompt, Which reads the Metadata Table (Presentation Table.Column Name, populated using the Metadata Dictionary)
    And Create a report with One Column and the Column Fx like @{var_dynamic_columns}{'"Time"."Year","Time"."Month"'}
    With this, OBIEE is rewriting the Logical SQL Currently as "Select "Time"."Year","Time"."Month" from "A - Sample Sales" "
    But getting an error
    The number of columns returned in retrieving column metadata was invalid (expected: 1; received: 2)
    So we want to see, if we can rewrite the Advanced XML of the Report to have dynamic columns based on the Values from the Presentation Variable.
    Please help me if this is a viable solution or any other better solution.

  • Design pattern for converting multiple complex Java objects to XML

    What is the traditionally accepted high performance mechanism for converting Java objects to XML? Some options I have explored are:
    1. SAX-JAXP
    2. DOM-JAXP
    3. JAXB
    4. Castor
    Which of these usually performs the best for large, complex objects which contain multiple subobjects?
    Thanks.

    Take a look at XStream. It will simplify your life considerably.
    Typical code snipped
    XStream xStream = new XStream();
    xStream.toXML(someJavaObject);That's it. Regarding the others...
    1. SAX-JAXP
    Can be used for XML -> Java Objects, but you have to write significant amounts of ugly, high maintainenance code
    2. DOM-JAXP
    Slower and more memory intensive than SAX because you need to read the whole object into memory first. Just as ugly and high maintenance.
    3. JAXB
    Actually very good for going from a POJO to XML, but rubbish in the opposite direction. The worst part is it adds an extra step to your build process as you need to tell it to generate and compile the source for doing this.
    4. Castor
    Not used it since JAXB came out. Works pretty much in the same way but also supports XML -> POJOs.

  • XML to Java Objects

    Hi,
    In our existing project we are using JDK / JRE 1.3.
    We need to add a module wherein we need to pick up an XML object (from MQ) and convert it into a Java Object.
    I was initially planning to use JAXP, but it appears that it needs Java 1.4 (or above). Is it ? So what is the other option available ?
    Is JDOM a worthwhile alternative ? Would it be supported on Java 1.3?or any other suitable alternative.
    Kindly advice as need to finalize on this as soon as possible.
    Thanks,
    MD

    You may have to roll your own - last time I was working with 1.3 there wasn't anything out there for it, but that was a couple of years ago.
    If the schema is fixed, you can pull parse, otherwise use SAX, a LinkedList as a stack and a map of element name -> content handler to populate the objects. If it's not a performance bottleneck*, you can get a long way just using reflection rather than having to write specific handling code for each attribute.
    Pete
    *most of what I do is aerospace simulation, so our messages might say 'run 100,000 simulations that cover all of the flight envelope', which then spawns a 15,000 cpu hour process, so it's at the opposite extreme to something like a SMS service hub, where there's almost no processing and it's all parsing, so optimising the XML for performance for us is irrelevent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Country ,state and city checklist XML by JAVA

    Hi friends,
    I have textboxes for entering the country ,state and city values and all these 3 fields are related by primary/foreign keys.
    I wan now store and retrieve values entered by users for country state and city by xml files .I also wan all these 3 field to be interrelated so that based on value of country I can populate the related states dropdownlist and based on value of state I can populate the related cities dropdownlist.Can some one pls answer my question about STORING AND RETRIEVING COUNTRY STATE AND CITY FIELDS USING XML FILES?
    I also did this application using string(short cut) way but is not efficient and all I want is direct modification in XML file by java?
    I didnt put my codes here bcos it so long and still if any one want my codes i wll email u sperately.
    All I need is any example approach for this kind?
    Any one help will be appreciated...

    Using XMLEncoder
    by Philip Milne
    This article covers advanced use of XMLEncoder, showing how it can be configured to create archives of any Java objects -- even when they don't follow the JavaBeans conventions. We include examples of how to make properties 'transient' and how to create archives that call constructors with arguments, use static factory methods, and perform non-standard initialization steps. We also cover exception notification, the 'owner' property (which can be used to a link an archive to the outside world), and methods for creating internationalized archives.
    http://java.sun.com/products/jfc/tsc/articles/persistence4/index.html

  • Xml to java object

    Hi
    What is an easy way to generate an java object from xml
    Thanks very much

    Using DOM or JDOM (http://xml.apache.org/xerces-j/, http://www.jdom.org/)
    It is equaly as easy to create a dom or a jdom obj, but most java programmers find JDOM more intuative to work with.
    Hope this helps!

  • Convert xml to java bean

    hi all
    i want to know how to convert a XML file to a java bean and this bean should be integrated with obejectweb,a open source middleware.
    1. how to create beans in NetBeans5.5
    2. how to run the bean
    3. how to connect the xml file to a bean program

    I think you need to start over and read a few tutorials. You cannot "run" a bean (unless it has a main() method but that would be very non-standard). You should not worry about which IDE you are using (Eclipse, NetBeans, etc.) And you do not "connect" the XML file to the bean, which again is not a program.
    The technologies you want to use will be JAXB (java XML binding) or Apache's XMLBeans. Both will require you to write a XML schema, which those API's can then use to create JavaBeans for you. There are tutorials for JAXB here at Sun and at Apache for XMLBeans.
    - Saish

  • Converting XML into a Object

    Hi,
    I'm trying to convert an xml object to a plain actionscript
    3.0 object. I've looked at SimpleXMLDecoder but without much luck.
    Any help or advice would be appreciated

    Have you tried
    [code]
    var data:Object = xmlData as Object;
    [/code]
    Although one of the capabilities with AS3 and E4X is that xml
    data is accesible as an object. I mean
    xmlData.node1.node2.(@attribute1) etc...

  • How to get xml into java object

    yo
    i want to get the xml doc into some object like Document
    i have downloaded code:
    public class Echo extends org.xml.sax.helpers.DefaultHandler
    this class compiles fine but when i instantiate the class in code i get:
    "Exception in thread 'main' java.lang.NoClassDefFoundError: org/xml/sax/helpers/DefaultHandler"
    Please, what does this mean and how do i get this to recognise that i want to use a specific parser
    thanks a lot

    You are probably not specifying the XML jar files (xalan.jar & xerces.jar) on the run line. What is the command you are using?
    Actually, which "jars" you use is dependent on which version of the XML Java release you downloaded (Winter or Fall).

Maybe you are looking for

  • Can't see new contacts added to iphone during sync

    During my iphone sync i used to see a window that would pop up indicating any changes in the address book and any new contacts to add during the sync then i would hit Sync Contatcs and it would add the new information to the address book and iphone a

  • Using a variable to refer to an object's ID

    Is there a way to replace "comboBox1" in the following line of script code with a variable which contains the text "comboBox1"?      comboBox1.dataProvider = dataArray; I was thinking something like this, but of course this doesn't work---doesn't lik

  • Time Machine External Hard Drive Back Up

    I am wondering if there is a way to back up on time machine an external hard drive connected to my airport extreme. Here is my set-up: iMac with a 2TB external hard drive connected via firewire to the actual iMac in the back airport extreme connected

  • Making animated gifs in Photoshop Elements 11

    Is there a way to color and/or adjust the lighting on all of the frames/layers of a gif at one time? I've been trying to adjust the brightness of a twenty-layer gif, but it's a pain in the butt to have to go through each layer and try to match the sa

  • Data type in column definition

    Hi, I create a table with column called "Direction of Travel code ". The travel codes in the functional spec are numbers. In the column definition which one is efficient to define the data type as number or varchar? Code 1       2       3       4