XML and Java

I am new in using xml in java, can any one tell me how to call XML file in java and how to read from it .
Regards
rajin

Look at the XML chapters of the J2EE 1.4 Tutorial:
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html
-Ian Evans

Similar Messages

  • NEW TO XML AND JAVA

    hi, I'm new to xml, actually I'm taking a course in xml and I should choose a certain project related to xml.
    I want to ask about xml and java
    the things that I know about java is some classes ( I made a program of bouncing ball in java and changed some java game programs). but I need to know how to use java in databases and how to relate it to xml
    Is it too dificult or I can learn it knowing that I'm ready to learn and already I'm learning xml.
    If anyone wants to help me please send me links to some websites where it is simple to learn java .
    Also if any one can give me an example of a certain project that can be done easily using java and xml u'll be more than welcome

    Check the JAVA XML Tutorials provided by the Java Site.

  • I'd like to load images using XML and Java - hints??

    I have a XML files that are created on a timed basis....they describe a photo and point to a dir where the photo is stored...like...
    <image>
    <user>bill</user>
    <img>photo.jpg</img>
    <img_dir>'/tmp/photos'</img_dir>
    </image>
    I'd like to write a Java program that parses the XML and loads the images, data into Oracle.
    Suggestions on Oracle tools, downloads that will help me accomplish this???
    Thanks!

    I pass a URL and then when I parse the XML I download the file from the URL.
    A.

  • 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

  • New to XML - what can XML and java do thogether - brief examples please

    I am new to XML and relatively new to Java, thought not new to programming. I am still trying to figure out what can XML do for me in practical terms and when I should use it. Thanks for any examples of when to use XML in conjunction with Java.

    xml : Think of it in terms of business solutions, the way you would think of HTML for drawing fun web-pages.
    java : If you know anything about databases you would know you can embed java with sql E.T.C.
    Therefore because of the fast response times and the amount of constant interaction for business purposes you will need a database type that is strong to handle XML, therefore with such new technology you will be able to use xml databases with java too.
    l am sorry : XML Technology is not more simple than that to explain.
    If you are a christian or jew it is like saying to someone explain the bible,the prophets,the old and new testament in one sentence!!!You get it.What one can do is slightly break-up the bible and say there's an old and new testament.The old testament refers to the time before Jesus, AND the new testament refers to After Jesus, THE PROPHETS RELATE MORE TO THE TIME BEFORE Jesus.
    You can then ask me who is jesus???
    And thats a tricky question in its self becuse it depends on one's thinking(concept)
    I HOPE IT HELPS YOU !!!!
    GOD DAY MATE!!

  • XML and Java Store Procedures

    I have written JDBC Classes that are using OracleXMLObject and they are successfully working outside of Oracle.
    I can successfully load them and create procedures for them. But, when I call them, I'm told that method does not exist.
    Please help, can you provide a working example?
    Regards,
    Bruce

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Mark Abram ([email protected]):
    Can you post some snippets of your code
    so we can have a better idea what you trying to do?<HR></BLOCKQUOTE>
    Dear Mark,
    Here is the code:
    import java.sql.*;
    import java.math.*;
    import oracle.xml.sql.query.*;
    import oracle.jdbc.*;
    import oracle.jdbc.driver.*;
    //Title:
    //Version:
    //Copyright: Copyright (c) 1999
    //Author: Bruce Kearney
    //Company: Atrion International
    //Description:
    public class IncidentTypeDB {
    // public static void main(String args[]) throws SQLException
    public void getEverything()
    try
    Connection connection = new OracleDriver().defaultConnection();
    OracleXMLQuery query = new OracleXMLQuery(connection, "select " +
    "incidenttypeidseq, incidenttype from incident_type");
    query.setMaxRows(query.MAXROWS_ALL);
    query.setRowsetTag("ROOTDOC");
    query.setRowTag("DBROW");
    String xmlString = query.getXMLString();
    System.out.println(xmlString);
    connection.close();
    } catch (SQLException e)
    System.out.println("Error retrieving record.");
    System.out.println(e.toString());
    return;
    } catch (Exception e)
    System.out.println("Error connecting to database.");
    System.out.println(e.toString());
    return;
    Regards,
    Bruce
    null

  • XML to Java and back again

    Okay, I've seen this question asked many times and I don't see a lot of great solutions. I've been searching for the last hour and looked at xBeans, XMLBeans, xStream, you name it. Anyway, what I want to do is model my XML and Java objects (if I can't auto-generate the classes) and then at runtime the XML should be loaded directly into the data model. I know that writing a custom parser is old school and there are tools to do this for me but I can't seem to find what I need. What do you recommend for doing this?

    Check out the Commons Digester.
    The Digester package lets you configure an XML -> Java object mapping module, which triggers certain actions called rules whenever a particular pattern of nested XML elements is recognized.
    You can't get any better than this....in my opinion.
    Good Luck!

  • XML and its influence over program design (2 issues)

    I have 2 open questions about XML and Java. I apologise if they are not clear-cut or specific enough, but really I am fishing for sound advice.
    I am trying to develop a J2EE application but find myself stuttering at an early stage because I cannot decide on the best design for my application. Part of my problem is a lack of experience with the different J2EE technologies/API (especially XML APIs), and the realisation that there is 101 ways to do what I want to do.
    A major issue is this: my application basically is concerned with representing conversations between the server and a user, e.g. a simple sequence of yes/no questions asked by the server to the user, which the user replies to in turn. I believe that the XML format would be a very suitable way to represent these conversations. My first question is:
    * Should the decision to use XML as a storage format influence the design of the rest of the program? I feel that in choosing XML to represent the conversation data, I am stuck thinking about the rest of my program in a XML way (i.e. doing everything using a DOM etc.). Am I right in thinking that my program should be designed in such a way that an XML-based storage system could be easily interchanged with, say, a relational flat-tabled database?
    My second question is:
    * Imagine that each conversation contains one or more questions, and there are, say, 4 different types of question (e.g. yes/no, multiple choice, etc.). Each of these needs to be handled in a different way. Is there a good pattern or recommended way of handling this sort of situation in code, ideally avoiding a big 'if' or switch statement (e.g. if the node is of "ABC" type do this, else if it is "yes/no"...). It would be great if one could easily add new types of question to the XML and then similarly one can make easy additions to the code to cope with these new cases.
    Thank you very much indeed for any advice.
    Greg

    I am trying to develop a J2EE application but find
    myself stuttering at an early stage because I cannot
    decide on the best design for my application. Part of
    my problem is a lack of experience with the different
    J2EE technologies/API (especially XML APIs), and theThat's nothing to be ashamed of. And realising that you lack experience and trying to remedy that is a good sign.
    A major issue is this: my application basically is
    concerned with representing conversations between the
    server and a user, e.g. a simple sequence of yes/no
    questions asked by the server to the user, which the
    user replies to in turn. I believe that the XML
    format would be a very suitable way to represent
    these conversations. My first question is:
    XML might be overkill if it's just a question followed by an answer and neither contains complex hierarchical data structures.
    * Should the decision to use XML as a storage format
    influence the design of the rest of the program? ICertainly not.
    XML should represent data structures that are natural to your program, thus becoming a tool rather than forcing its structure upon you.
    feel that in choosing XML to represent the
    conversation data, I am stuck thinking about the rest
    of my program in a XML way (i.e. doing everything
    using a DOM etc.). Am I right in thinking that my
    program should be designed in such a way that an
    XML-based storage system could be easily interchanged
    with, say, a relational flat-tabled database?
    Flexibility is good to keep in mind, but at the moment I'd worry about just getting something to work.
    * Imagine that each conversation contains one or more
    questions, and there are, say, 4 different types of
    question (e.g. yes/no, multiple choice, etc.). Each
    of these needs to be handled in a different way. Is
    there a good pattern or recommended way of handling
    this sort of situation in code, ideally avoiding a
    big 'if' or switch statement (e.g. if the node is of
    "ABC" type do this, else if it is "yes/no"...). It
    would be great if one could easily add new types of
    question to the XML and then similarly one can make
    easy additions to the code to cope with these new
    cases.
    Think of a factory that creates the handlers on the fly based on the actual message received.
    If the factory makes use of some mapping construct to do so there's no need for any conditionals at all in your decision tree.
    I've myself used XML structures successfully to define such mappings (and so have others) on disc, but simple ones can be easily represented using just a properties file.

  • Problems with character displaying from XML to Java

    Hi to all!
    I am making a flash chat program which basically takes english and chinese
    and talk to java using XML and java server distribute this message to all users,
    While simply using java as a distributor of the data was fine, but when I try to
    keep records of the chat into the mysql database, I realized that all the
    chinese characters are displayed in random characters.
    After some thought, I realized that flash using ASCII number representation
    for each chinese word imay be different from the Java ASCII number representation, therefore, when Java sends
    these ASCII characters to the mysql database, the words is no longer the words I wanted.
    I am using a brute force, which on the flash side, I took the ASCII code of each chinese character that I
    typed and use break and send them to java and recoded in java with java's Chinese character
    and send to the mysql database, well, it works(I tried) but I need to type up at least 3000 characters!!!!!!!!
    this is insane!
    I am also wonder if the problem comes because Java encode Chinese in unicode, so
    it does not recognize the ASCII, and therefore, the result is for sure weird.
    If so, what do I need to do in order to convert ASCII into Unicode????
    sincerely,
    Suansworks

    hello.
    flash have some problems by utf but it seems that your problem is with mysql database because if you want to put utf in mysqk database you need to get latest version that is beta or alpha. please it using with other database that supports utf.

  • Toplink xml binding session.xml and servlet

    I made a project with toplink-jaxb mapping
    with simple pojo object it works fine.
    I made another project with servlet
    and the same session.xml and java classes
    but when my process start it throw an exception :
    jaxbexception : Provider oracle.toplink.ox.jaxb.JAXBContextFactory could not be instantiated:
    It is like the process could not read the session.xml files, but this file and two xml file for the mapping are in the classpath (in WEB-INF/classes).
    Have i to put these files in another place ?
    Thanks.

    Hi,
    thank you for your response but
    here is the code :
    javax.xml.bind.JAXBContext jaxbContext = javax.xml.bind.JAXBContext.newInstance(
    "fr.cnav.cramse.pgpe.contactsnationaux"),this.getClass().getClassLoader());
    but i still got the same exception :
    05/03/01 08:24:33 exceptionProvider oracle.toplink.ox.jaxb.JAXBContextFactory could not be instantiated: java.lang.NoSuchMethodError: oracle.toplink.publicinterface.Session oracle.toplink.tools.sessionmanagement.SessionManager.getSession(oracle.toplink.tools.sessionconfiguration.XMLSessionConfigLoader, java.lang.String, java.lang.ClassLoader, boolean, boolean)
    I have also a stange message in the log window in jdev :
    Cutting log (size: 101767, max: 100000)Component returned failure code: 0x80470002 (NS_BASE_STREAM_CLOSED) [nsIFileOutputStream.write]Component returned failure code: 0x80470002 (NS_BASE_STREAM_CLOSED) [nsIFileOutputStream.write]Component returned failure code: 0x80470002 (NS_BASE_STREAM_CLOSED) [nsIFileOutputStream.write]Cutting log (size: 101866, max: 100000)Error cleaning up log: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsISeekableStream.seek]
    Thank you for your help.

  • Printinting XML in JAVA

    I have the following XML file and the java file to read the xml contents.
    I compiled the java file.When i read it it says,
    parsing error line 0, uri null
    d:\book.xml not found.
    the xml and java file are in same path only. whats the problem?
    following is the code:
    java file
    import java.io.File;
    import org.w3c.dom.Document;
    import org.w3c.dom.*;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    public class ReadAndPrintXMLFile{
    public static void main (String argv []){
    try {
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    File fobj=new File("D:\\book.xml");
    System.out.println("file :"+fobj);
    Document doc = docBuilder.parse(fobj);
    // normalize text representation
    doc.getDocumentElement ().normalize ();
    System.out.println ("Root element of the doc is " + doc.getDocumentElement().getNodeName());
    NodeList listOfPersons = doc.getElementsByTagName("person");
    int totalPersons = listOfPersons.getLength();
    System.out.println("Total no of people : " + totalPersons);
    for(int s=0; s<listOfPersons.getLength() ; s++){
    Node firstPersonNode = listOfPersons.item(s);
    if(firstPersonNode.getNodeType() == Node.ELEMENT_NODE){
    Element firstPersonElement = (Element)firstPersonNode;
    NodeList firstNameList = firstPersonElement.getElementsByTagName("first");
    Element firstNameElement = (Element)firstNameList.item(0);
    NodeList textFNList = firstNameElement.getChildNodes();
    System.out.println("First Name : " + ((Node)textFNList.item(0)).getNodeValue().trim());
    NodeList lastNameList = firstPersonElement.getElementsByTagName("last");
    Element lastNameElement = (Element)lastNameList.item(0);
    NodeList textLNList = lastNameElement.getChildNodes();
    System.out.println("Last Name : " + ((Node)textLNList.item(0)).getNodeValue().trim());
    NodeList ageList = firstPersonElement.getElementsByTagName("age");
    Element ageElement = (Element)ageList.item(0);
    NodeList textAgeList = ageElement.getChildNodes();
    System.out.println("Age : " + ((Node)textAgeList.item(0)).getNodeValue().trim());
    }//end of if clause
    }//end of for loop with s var
    }catch (SAXParseException err) {
    System.out.println ("** Parsing error" + ", line " + err.getLineNumber () + ", uri " + err.getSystemId ());
    System.out.println(" " + err.getMessage ());
    }catch (SAXException e) {
    Exception x = e.getException ();
    ((x == null) ? e : x).printStackTrace ();
    }catch (Throwable t) {
    t.printStackTrace ();
    }//end of main
    FOllowing is the XML file:
    <?xml version="1.0"?>
    <book>
    <person>
    <first>Kiran</first>
    <last>Pai</last>
    <age>22</age>
    </person>
    <person>
    <first>Bill</first>
    <last>Gates</last>
    <age>46</age>
    </person>
    <person>
    <first>Steve</first>
    <last>Jobs</last>
    <age>40</age>
    </person>
    </book>

    I have the following XML file and the java file to
    read the xml contents.
    I compiled the java file.When i read it it says,
    parsing error line 0, uri null
    d:\book.xml not found.
    the xml and java file are in same path only. whats the
    problem?
    following is the code:
    java fileMalisun,
    Is your java pgm. and XML file in the root directory of D: drive? By writing code as File fobj = new File("D:\\book.xml"); you indicate that the file is in the root directory of your D: drive. I just changed the following line:
    File fobj=new File("D:\\book.xml");to
    File fobj=new File("book.xml");and the program worked fine. I hope this helps.

  • How use XSD and Java? What classes/methods?

    I want to use an XSD instead of a DTD with my XML and Java. Does anyone know the classes/methods I should use to do this? Is it even possible? Can you send sample code?

    here is the helper function... hope it helps...
    import java.io.IOException;
    import java.math.*;
    import java.text.*;
    import org.xml.sax.Attributes;
    import org.xml.sax.ContentHandler;
    import org.xml.sax.ErrorHandler;
    import org.xml.sax.Locator;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import org.xml.sax.XMLReader;
    import org.xml.sax.helpers.XMLReaderFactory;
    public class SAXParserDemo
         public SAXParserDemo()
         public void performDemo(String uri)
              System.out.println("Parsing XML file: " + uri + "\n\n");
              ContentHandler contentHandler = new MyContentHandler();
              ErrorHandler errorHandler = new MyErrorHandler();
              try
                   XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
                   parser.setContentHandler(contentHandler);
                   parser.setErrorHandler(errorHandler);
                   parser.setFeature("http://xml.org/sax/features/validation", true);
                   parser.parse(uri);
              catch(IOException e)
                   System.out.println("Error reading URI: " + e);
              catch(SAXException e)
                   System.out.println("Error in parsing: " + e);
         public static void main(String[] args)
              if(args.length != 1)
                   System.out.println("Usage: java SAXParserDemo [XML URI]");
                   System.exit(0);
              String uri = args[0];
              SAXParserDemo parserDemo = new SAXParserDemo();
              parserDemo.performDemo(uri);
    class MyErrorHandler implements ErrorHandler
         public void warning(SAXParseException exception) throws SAXException
              throw new SAXException("Warning encountered."+exception);
         public void error(SAXParseException exception) throws SAXException
              throw new SAXException("Error encountered: "+exception);
         public void fatalError(SAXParseException exception) throws SAXException
              throw new SAXException("Fatal error encountered."+exception);
    class MyContentHandler implements ContentHandler
         private Locator locator;
         public void setDocumentLocator(Locator locator)
              //System.out.println("     * setDocumentLocator() called");
              this.locator = locator;
         public void startDocument() throws SAXException
              //System.out.println("System Message: Parsing begins...");
         public void endDocument() throws SAXException
              //System.out.println("System Message: ...Parsing ends.");
         public void processingInstruction(String target, String data) throws SAXException
              //System.out.println("System Message: PI: Target: "+target+" and Data: "+data);
         public void startPrefixMapping(String prefix, String uri)
              //System.out.println("System Message: Mapping starts on prefix "+prefix+" mapped to URI "+uri);
         public void endPrefixMapping(String prefix)
              //System.out.println("System Message: Mapping ends on prefix "+prefix);
         public void startElement(String namespaceURI, String localName, String rawName, Attributes atts) throws SAXException
              //System.out.println("System Message: startElement: "+localName);
              if(!namespaceURI.equals(""))
                   //System.out.println("System Message: in namespace "+namespaceURI+" ("+rawName+")");
              else
                   //System.out.println("System Message: has no associated namespace");
              int i;
              for(i=0;i<atts.getLength();i++)
                   //System.out.println("System Message: Attribute: "+atts.getLocalName(i)+"="+atts.getValue(i));
         public void endElement(String namespaceURI, String localName, String rawName) throws SAXException
              //System.out.println("System Message: endElement: "+localName+"\n");
         public void characters(char[] ch, int start, int length) throws SAXException
              String s = new String(ch, start, length);
              //System.out.println("System Message: characters: "+s);
         public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
              String s = new String(ch, start, length);
              //System.out.println("System Message: ignorableWhitespace: ["+s+"]");
         public void skippedEntity(String name) throws SAXException
              //System.out.println("System Message: Skipping entity: "+name);
    }

  • Using XML or Java Scripting

    Hello all
    i am new to obi ee and i wanna know how can we use the codes of xml and java scripting in it and i am sitting on the client system...Do i need to change some files on server???
    thanks in advance,
    pankaj

    You mean like in this thread? Re: Creating a Popup Box / List of Values on a Dashboard
    What's the idea behind it?
    Why this and not a prompt?
    Input mask for write-back?
    Cheers,
    C.

  • Create XML dynamically from schema and Java bean

    Hi,
    I'm looking for suggestions on the best approach to create an XML file programatically from a schema and Java bean.
    The schema used is not fixed and may vary with each request so a dynamic way to create the XML is required.
    Is there an API available that allows me to achieve this easily? Any help would be appreciated to point me in the right direction.
    Thanks.

    XMLBeans or JAXB should work for you.
    - Saish

  • Simple XML to Text onversion using XSLT and Java?

    Hi all!
    I'm completly new to using XSLT and Java and are trying to convert a XML file into a ordinary Textfile that I am gonna import into another application.
    I started up writing a ordinary XML parser in Java which interpreted the XML file, but realized later on that it was possible to do with a ordinary XSLT.
    So far it is a 2-step process right now, I've tied my XSLT to the XML file and then just open the XML file up in a ordinary browser and then get the result.
    I found an example (http://www.onjava.com/pub/a/onjava/excerpt/java_xslt_ch5/index.html?page=3) where u hook up a XML file and a XSL file separately and the process it, and dump it to Stdout. But do I need to hook up a XSL file like this when the XML file is tied to a XSL file internally?

    Just to give you an example to show you how easy it is: http://www.daniweb.com/forums/thread137587.html

Maybe you are looking for

  • How to run .exe files on macbook pro

    Just bought my first macbook pro the other day.  I absolutely love it.  Much better than the windows boxes.  I wanted to run some '.exe' files on my new laptop but was not successful finding anything on the market to use without purchasing a full OS

  • IDES ECC 5.0, BW, FI, HR

    Hi, I am new to SAP world and looking for IDES ECC 5 so I can learn SAP better. Please share your IDES ECC 5 with installation documentation. I am willing to pay a price via paypal. Please email me at [email protected] Please help. Thank you so much.

  • JPanel, GridbagLayout - change size when click event

    Hello i have a problem. I using a JPanel with different components, which are ordered with a gridbag layout. So, when i click on the panel the size the textarea change the size. import java.awt.*; import java.awt.event.*; import javax.swing.*; import

  • Color shift when converting .mov file exported from Macromedia Flash

    I'm trying to convert quicktime file exported from Flash into any other format using Quicktime Pro 7.0.4 and I get substantial color shift. Here's the picture: http://img525.imageshack.us/img525/1518/screen3ov.jpg On the the left is the initial file,

  • IWeb site vanished! (Lion)

    Hi I used Finder to find my Domain and then dragged the Domain icon onto my Desktop. Now I can't find my site anywhere! It was the only site I had on iWeb so now when I open iWeb, it just opens the template menu, as if my site never existed. What the