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

Similar Messages

  • 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

  • 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 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

  • 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?

  • 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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • XMl and Java object mapping

    I need to map java objects with XMl Node or XML Elements.
    My java objets get some attributes, for instance name,color ...
    and i need an output like:
    <OBJECT_OF_TYPE_XXX>
    <NAME>scott</NAME>
    <COLOR>red</COLOR>
    </OBJECT_OF_TYPE_XXX>
    Any idea?
    Thanks
    Maurice

    You can try JAXB which includes a compiler that generates classes based on the XML Schema for your xml structure. It also features the possibility to convert between xml and the generated objects.
    Take a look at chapter 9 and 10 at http://java.sun.com/webservices/docs/1.1/tutorial/doc/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!

  • Converting from PDF directly to Java Objects/XML (and PDF format questions)

    Hi,
    I posted this originally in the Acrobat Windows forums but was told I might have more luck here, so here goes:
    I am desperately trying to find a tool (preferably open source but commercial is fine also) that will sit on top of a PDF and allow me to query it's text for content and formatting (I don't care about images). I have found some tools that get me part of the way there, but nothing that seems to provide an end-to-end solution but is quite lightweight. My main question is WHY are there so many tools that go from PDF to RTF, and many tools that go from RTF to XML, but NONE that I can find that go PDF to XML.
    To clarify, by formatting I simply mean whether a line/block of text is bold/italic, and its font size. I am not concerned with exact position on the page. The background is that I will be searching PDFs and assigning importance to whether text is a heading/bodytext etc. We already have a search tool in place so implementing a pure PDF search engine is not an option. I need a lightweight tool that simply allows me to either make calls directly to the PDF OR converts to XML which I can parse.
    Some tools I have tried:
    1) PDFBox (Java Library) - Allows the extraction of text content easily, but doesn't seem to have good support for formatting.
    2) JPedal (Java Library) - Allows extraction of text content easily, and supports formatting IF XML structured data is in the PDF (not the case for my data).
    3)  Nitro PDF (Tool) + RTF to XML (script) - This works quite nicely and shows that PDF to XML is possible, but why do I have to use 2 tools? Also, these are not libraries I can integrate into my app.
    4) iText (Java Library) - Seems great at creating PDFs but poor at extracting content.
    I don't really expect someone to give me a perfect solution (although that would be nice!).
    Instead, what I'd like to know is WHY tools support PDF to RTF/Word/whatever retaining formatting, and other tools support RTF to XML with the formatting information retained. What is it about PDF and RTF/Word that makes it feasible to convert that way, but not to XML. Also, as I found in 3) above, it is perfectly feasible to end up as XML from PDF, so why do no tools support this reliably!
    Many thanks for any advice from PDF gurus.

    XML doesn't mean anything - it's just a generic concept for structuring
    information.  You need a specific GRAMMAR of XML to mean anything.  So what
    grammar would you use?  Something standard?  Make up your own?
    However, there are a number of commercial and open source products that can
    convert PDF to various XML grammars - SVG, ABW, and various custom grammars.
    But the other thing you need to understand is that most PDF files do not
    have any structure associated with them (as you saw when using JPEDAL).  As
    such, any concepts of paragraphs/sections/tables/etc. Are WILD GUESSES by
    the software in question.

  • 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]

  • How to add DTD syntax line into XML using java code

    Hi,
    I am building xml file with java, usiing document.createElement()
    and document.appendChild(element),
    like that
    now i need to add dtd file path and synatx in the top of the xml file,
    how can i do it through java code
    any body could help me
    i appreciate your help.
    thanks
    Durga

    Hi Suneetha,
    Thanks for your reply..
    Now i am getting docType in xml file but not in the format of what i want
    please look at my code
    i need
    <!DOCTYPE myRootElement SYSTEM "myXMLDTD.dtd" >
    but i am getting
    <!DOCTYPE myRootElement PUBLIC "" "myXMLDTD.dtd">
    There is change i need to get the SYSTEM in place of PUBLIC and i need to get rid of "" code between dtd and PUBLIC
    for this i am doing in my code as
    DocumentType theDocType = new DocumentImpl().createDocumentType ("SYSTEM","","myXMLDTD.dtd");
    Document theDoc = new DocumentImpl(theDocType);
    i dn't know what is the wrong ? i dn't know what are the parameters at what place to pass if you know any thing just let me know
    thanks in advance
    and i apperciate you help.
    Durga

  • How to bind dynamic xml with Java objects without xsd

    have a question, and hope someone here can help me.
    In my current project, I will get a xml file, containing some information of each user, and map them into a set of user objects.
    For each user, there are some fixed attributes, such as name, phone#, age, position, etc. The problem is, client can customize, and add new attibutes, such as address, favorite color, so there will be no xsd for the xml.
    What I want to do, is map fixed attributes to user object attributes, for example, name attribute to User.name, and they will have corresponding getters, and setters, but for custom attributes, I want to add them to a HashMap in User object, for example, use string "ADDRESS" as the key, and address as the value.
    Is there any way I can do this? Thank you very much for any help you can provide.

    It would not be too hard to do in regular code.
    First, make a HashSet with the Strings for the names of the known attributes that will be processed with setters.
    Then, get the NamedNodeMap via getAttributes(). That will give you all attributes -- both the ones you will handle with your setters and the ones you will handle via a HashMap.
    Then, loop through the NamedNodeMap. For each attribute, get the name and value. If the name is in the HashSet of known values, process it with a list of
    if ( attName.equals( "name" ))
        whatever.setName( value );
       continue;
    }If it is not in the HashSet, then set the value into your HashMap with the name and value.
    There is no standard way to do this.
    Dave Patterson

  • Help with Deserializer XML to Java Object

    Hello,
    I need Deserializer a xml to Object using SAX or another technology
    My code is the follow:
    *          java.io.Writer stringWriter = new StringWriter();*
    *          org.apache.axis.encoding.SerializationContext context0 = new SerializationContext(stringWriter,*
    *                    null);*
    *          javax.xml.namespace.QName qname = new javax.xml.namespace.QName(*
    *                    "http://xxxxxx", "WSUpdateDocumentResponse");*
    *          org.apache.axis.encoding.ser.BeanSerializer serializer = new BeanSerializer(WSUpdateDocumentResponse.class,*
    *                    qname);*
    *          serializer.serialize(qname, null, resp, context0);*
    *          String deserializaXML = stringWriter.toString();*
    The variable deserializaXML contains el XML as String.
    +<ns1:WSUpdateDocumentResponse xmlns:ns1="http://xxxxxxx">+
    +<documentCode xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">+
    +43723+
    +</documentCode>+
    +<updateMessageList xsi:type="ns1:ArrayOfWSUpdateMessage" xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>+
    +</ns1:WSUpdateDocumentResponse>+
    That's is ok, but the problem is when, I try The reverse engineering.
    The code is the following:
    *          org.apache.axis.encoding.Deserializer bean = WSUpdateDocumentResponse.getDeserializer(deserializaXML,*
    *                                                                                     WSUpdateDocumentResponse.class,*
    *                                                                                     new javax.xml.namespace.QName("http://xxxxxx, "WSUpdateDocumentResponse"));*
    *          WSUpdateDocumentResponse resp2 = (WSUpdateDocumentResponse)bean.getValue();*
    The object not load correctly, all variables are null.
    Any idea?
    Thanks.
    Regards
    P.D.: The bean WSUpdateDocumentResponse was generated with Axis 1.2RC2, i haven't another option by the dependences project

    Hi,
    Check the methods like getElementById() and getElementByTagName and the corresponding Namespace aware equivalents. Once you have your orders, you can iterate over them and build your target xml.
    Personally, I think your teacher sold you a lemon. This is a job that is best done using XSLT and doing this using dom is like using your bicycle to get to saturn when you have a starship available.
    cheers,
    vidyut

  • Parse of a xml file to an java object model

    Hello,
    I'm trying to do a program that receive an xml file and ought to create all the neccesary java objects according to the content of the parsed xml file.
    I've all the class created for all the objects that could be present into the xml and the idea is to go down in the tree of nodes recursively until it returns nodes more simple. Then, I create the last object and while I come back of the recursively calls, I create the objects more complex until I reached to the main object.
    Until now, I have part of this code, that is the one wich have to parse the parts of the xml.
    public static void readFile(String root){
              DocumentBuilderFactory factory = DocumentBuilderFactory
                   .newInstance();
              try {
                   DocumentBuilder builder = factory.newDocumentBuilder();
                   Scanner scanner = new Scanner(new File(root)).useDelimiter("\\Z");
                   String contents = scanner.next();
                   scanner.close();
                   Document document = builder.parse(new ByteArrayInputStream(contents.getBytes()));
                   Node node = null;
                   NodeList nodes = null;
                   Element element = document.getDocumentElement();
                   System.out.println(element.getNodeName());
                   NodeList subNodes;
                   NamedNodeMap attributes;
                   //if (element.hasAttributes())
                   visitNodes(element);
              } catch (ParserConfigurationException e) {
                   e.printStackTrace();
              } catch (SAXException e) {
                   e.printStackTrace();
              } catch (IOException e) {
                   e.printStackTrace();
         private static void visitNodes (Node node){
              for(Node childNode = node.getFirstChild(); childNode!=null;){
                   if (childNode.getNodeType() == childNode.DOCUMENT_NODE){
                        System.out.println("Document node Name " + childNode.getNodeName());
                        visitNodes(childNode);
                   }else if (childNode.getNodeType() == childNode.ELEMENT_NODE){
                        System.out.println("Node Name " + childNode.getNodeName());
                        if (childNode.hasAttributes()){
                             visitAttributes(childNode.getAttributes());
                        if (childNode.hasChildNodes()){
                             visitNodes(childNode);
                   }else if (childNode.getNodeType() == childNode.TEXT_NODE && !childNode.getNodeValue().contains("\n\t")){
                        System.out.println("Node value " + childNode.getNodeValue());
                   Node nextChild = childNode.getNextSibling();
                   childNode = nextChild;
         private static void visitAttributes(NamedNodeMap attributes){
              Node node;
              for(int i = 0; i < attributes.getLength(); i++){
                   node = attributes.item(i);
                   System.out.print(node.getNodeName() + " ");
                   System.out.print(node.getNodeValue() + " ");
                  }I don't know the use of childNodeType. For example, I expected that the XML tags with childs in his structure, enter by the option NODE_DOCUMENT and the tags without childs by the ELEMENT_NODE.
    But the most important problem I've found are the nodes [#text] because after one ELEMENT_NODE I always found this node and when I ask if the node hasChilds, always returns true by this node.
    Has any option to obtain this text value, that finally I want to display without doing other recursively call when I enter into the ELEMENT_NODE option?
    When one Node is of type DOCUMENT_NODE or DOCUMENT_COMMENT? My program always enter by the ELEMENT_NODE type
    Have you any other suggestions? All the help or idea will be well received.
    Thanks for all.

    Hello again,
    My native language is Spanish and sorry by my English I attemp write as better I can, using my own knowledge and the google traductor.
    I have solved my initial problem with the xml parser.
    Firstly, I read the complete XML file, validated previously.
    The code I've used is this:
    public static String readCompleteFile (String root){
              String content = "";
              try {
                   Scanner scanner = new Scanner(new File(root)).useDelimiter("\\Z");
                   content = scanner.next();
                   scanner.close();
              } catch (IOException e) {
                   e.printStackTrace();
              return content;
         }Now, I've the file in memory and I hope I can explain me better.
    I can receive different types of XML that could be or not partly equals.
    For this purpose I've created an external jar library with all the possible objects contained in my xml files.
    Each one of this objects depend on other, until found leaf nodes.
    For example, If I receive one xml with a scheme like the next:
    <Person>
        <Name>Juliet</Name>
        <Father Age="30r">Peter</Father>
        <Mother age="29">Theresa</Mother>
        <Brother>
        </Brother>
        <Education>
            <School>
            </school>
        </education>
    </person>
    <person>
    </person>The first class, which initializes the parse, should selecting all the person tags into the file and treat them one by one. This means that for each person tag found, I must to call each subobject wich appears in the tag. using as parameter his own part of the tag and so on until you reach a node that has no more than values and or attributes. When the last node is completed I'm going to go back for completing the parent objects until I return to the original object. Then I'll have all the XML in java objects.
    The method that I must implement as constructor in every object is similar to this:
    public class Person{
      final String[] SUBOBJETOS = {"Father", "Mother", "Brothers", "Education"};
      private String name;
         private Father father;
         private Mother mother;
         private ArrayList brothers;
         private Education education;
         public Person(String xml){
           XmlUtil utilXml = new XmlUtil();          
              String xmlFather = utilXml.textBetweenXmlTags(xml, SUBOBJETOS[0]);
              String xmlMother = utilXml.textBetweenXmlTags(xml, SUBOBJETOS[1]);
              String xmlBrothers = utilXml.textBetweenMultipleXmlTags(xml, SUBOBJETOS[2]);
              String xmlEducation = utilXml.textBetweenXmlTags(xml, SUBOBJETOS[3]);
              if (!xmlFather.equals("")){
                   this.setFather(new Father(xmlFather));
              if (!xmlMother.equals("")){
                   this.setMother(new Father(xmlMother));
              if (!xmlBrothers.equals("")){
                ArrayList aux = new ArrayList();
                String xmlBrother;
                while xmlBrothers != null && !xmlBrothers.equals("")){
                  xmlBrother = utilXml.textBetweenXmlTags(xmlBrothers, SUBOBJETOS[2]);
                  aux.add(new Brother(xmlBrother);
                  xmlBrothers = utilXml.removeTagTreated(xmlBrothers, SUBOBJETOS[2]);
                this.setBrothers(aux);
              if (!xmlEducation.equals("")){
                   this.setEducation(new Father(xmlEducation));     
    }If the object is a leaf object, the constructor will be like this:
    public class Mother {
         //Elements
         private String name;
         private String age;
         public Mother(String xml){          
              XmlUtil utilXml = new XmlUtil();
              HashMap objects = utilXml.parsearString(xml);
              ArraysList objectsList = new ArrayList();
              String[] Object = new String[2];
              this.setName((String)objects.get("Mother"));
              if (objects.get("attributes")!= null){
                   objectsList = objects.get("attributes");
                   for (int i = 0; i < objectsList.size();i++){
                     Object = objectsList.get(i);
                     if (object[0].equals("age"))
                       this.setAge(object[1]);
                     else
         }Each class will have its getter and setter but I do not have implemented in the examples.
    Finally, the parser is as follows:
    import java.io.ByteArrayInputStream;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.HashMap;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.Document;
    import org.w3c.dom.NamedNodeMap;
    import org.w3c.dom.Node;
    import org.xml.sax.SAXException;
    public class XmlUtil {
         public HashMap parsearString(String contenido){
              HashMap objet = new HashMap();
              DocumentBuilderFactory factory;
              DocumentBuilder builder;
              Document document;
              try{
                   if (content != null && !content.equals("")){
                        factory = DocumentBuilderFactory.newInstance();
                        builder = factory.newDocumentBuilder();
                        document = builder.parse(new ByteArrayInputStream(content.getBytes()));
                        object = visitNodes(document);                    
                   }else{
                        object = null;
              } catch (ParserConfigurationException e) {
                   e.printStackTrace();
                   return null;
              } catch (SAXException e) {
                   e.printStackTrace();
                   return null;
              } catch (IOException e) {
                   e.printStackTrace();
                   return null;
              return object;
         private HashMap visitNodes (Node node){
              String nodeName = "";
              String nodeValue = "";
              ArrayList attributes = new ArrayList();
              HashMap object = new HashMap();
              Node childNode = node.getFirstChild();
              if (childNode.getNodeType() == Node.ELEMENT_NODE){
                   nodeName = childNode.getNodeName();                    
                   if (childNode.hasAttributes()){
                        attributes = visitAttributes(childNode.getAttributes());
                   }else{
                        attributes = null;
                   nodeValue = getNodeValue(childNode);
                   object.put(nodeName, nodeValue);
                   object.put("attributes", attributes);
              return object;
         private static String getNodeValue (Node node){          
              if (node.hasChildNodes() && node.getFirstChild().getNodeType() == Node.TEXT_NODE && !node.getFirstChild().getNodeValue().contains("\n\t"))
                   return node.getFirstChild().getNodeValue();
              else
                   return "";
         private ArrayList visitAttributes(NamedNodeMap attributes){
              Node node;
              ArrayList ListAttributes = new ArrayList();
              String [] attribute = new String[2];
              for(int i = 0; i < attributes.getLength(); i++){
                   atribute = new String[2];
                   node = attributes.item(i);
                   if (node.getNodeType() == Node.ATTRIBUTE_NODE){
                        attribute[0] = node.getNodeName();
                        attribute[1] = node.getNodeValue();
                        ListAttributes.add(attribute);
              return ListAttributes;
    }This code functioning properly. However, as exist around 400 objects to the xml, I wanted to create a method for more easily invoking objects that are below other and that's what I can't get to do at the moment.
    The code I use is:
    import java.lang.reflect.Constructor;
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    public class UtilClasses {
         public Object UtilClasses(String package, String object, String xml){
              try {
                Class class = Class.forName(package + "." + object);
                //parameter types for methods
                Class[] partypes = new Class[]{Object.class};
                //Create method object . methodname and parameter types
                Method meth = class.getMethod(object, partypes);
                //parameter types for constructor
                Class[] constrpartypes = new Class[]{String.class};
                //Create constructor object . parameter types
                Constructor constr = claseObjeto.getConstructor(constrpartypes);
                //create instance
                Object obj = constr.newInstance(new String[]{xml});
                //Arguments to be passed into method
                Object[] arglist = new Object[]{xml};
                //invoke method!!
                String output = (String) meth.invoke(dummyto, arglist);
                System.out.println(output);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
              return null;
         }This is an example obtained from the Internet that I've wanted modified to my needs. The problem is that when the class calls this method to invoke the constructor and does not fail, this does not do what I expect, because it creates an empty constructor. If not, the parent class gives a casting error.
    I hope that now have been more clear my intentions and that no one has fallen asleep reading this lengthy explanation.
    greetings.

  • EXCEL XML into XML - using MessageMapping

    Hi
    I have an XSLT that I use to convert an Excel XML into another XML format.
    But I wonder if there a way to do this via the XI Message Mapping instead?. I have tried but I am stuck at the moment trying to identify particular rows. For instance I need to fill the <desc> tag from the 3rd Cell.
    [code]
    Original Excel data
           Cell1 Cell2   Cell3            Cell4   Cell5
    Row1 | AY02  403KITA Concentrator Kit $91.00  22-01-2005
    Row2 | AY02  401KITC Oxygen Reg/Flow  $65.00  08-09-2006
    [/code]
    Input Source file (a cut down version...)
    [code]
    <Workbook>
    <Worksheet>
      <Table>
       <Row>
         <Cell>
            <Data>AY02</Data>
         </Cell>
         <Cell>
            <Data>403KITA</Data>
         </Cell>
         <Cell>
            <Data>Concentrator Kit</Data>
         </Cell>
         <Cell>
            <Data>$91.00</Data>
         </Cell>
         <Cell>
            <Data>22-01-2005</Data>
         </Cell>
       </Row>
       <Row>
         <Cell>
             <Data>AY02</Data>
         </Cell>
         <Cell>
             <Data>401KITC</Data>
         </Cell>
         <Cell>
             <Data>Oxygen Reg/Flow Portable</Data>
         </Cell>
         <Cell>
             <Data>$65.00</Data>
         </Cell>
         <Cell>
             <Data>08-09-2006</Data>
         </Cell>
       </Row>
       </Table>
    </Worksheet>
    </Workbook>
    [/code]
    Target XML
    [code]
    <Batch>
      <items>
        <item>
          <catlgItemNum>403KITA</catlgItemNum>
          <desc>Concentrator Kit</desc>
          <unitPrice>$91.00</unitPrice>
        </item>
        <item>
          <catlgItemNum>401KITC</catlgItemNum>
          <desc>Oxygen Reg/Flow Portable</desc>
          <unitPrice>$65.00</unitPrice>
      </item>
    </items>
    </Batch>
    [/code]

    Hi Peter,
    Please create the following user-defined function (cache: context):
    public static void getIndexedValue(
         String[] a,
         String[] b,
         ResultList result,
         Container container) {
         //write your code here          
         Integer iB = new Integer(b[0]);
         result.addValue(a[iB.intValue()]);
    You can then set up the following mappings:
    Row - item
    Data (context Row) 
                          getIndexedValue - ...
    Constant [1, 2, 3]  /
    Best regards
    Joachim

Maybe you are looking for

  • Mail Receiver adapter - dynamic file name without mail package

    I know that we can get the dynamic attachment name using mail package... As per the FAQ Mail adapter, the Mail package use is deprecated and hence we do not want to go that route. I have seen the following wiki entry for setting the file attachment n

  • WSDL without SOAP Action (BTS.Operation?)

    Hi I got a WSDL without SOAP Action specified. I'm able to generate XSDs, set up a send port and  call an operation. Since I was calling a single web operation then I set up my Action at send port WCF config to be http://localhost/CarService/updateLo

  • Broadband router

    Hi, I'm moving to a new property, and have ordered broadband which will be activated in 2 weeks. The router is due to arrive on the same day as the broadband will be activated. If I'm not around on the day to sign for the router, will I be able to us

  • Getting Invalid Cursor Error

    Hi, I am having trouble with my code and it is generating an error in the alert logs and trace files. Can i ask for help? Fri Sep 02 19:20:33 2011 Errors in file D:\oracle\dumps\prod_ora_5312.trc: ORA-00600: internal error code, arguments: [17281], [

  • Making a phone calls on my macbook pro together wiyh my iPhone running iOS 8 I can not hear the people speking

    Hello When making a call from my contact list on my macbook pro, together with my ipone 6 the call is established but i Can not hear loud enough the person I am calling. I have tried with my head phones and still not working.  Can any one help.  Than