Starting Java with XML

Hi,
I am new to this forum. What will be the best place to start Java? I have a PC with Windows NT Operating Systems. I would like to read and write XML files from Java.
Thanks for your help.
Ajay

http://java.sun.com/docs/books/tutorial/getStarted/cupojava/index.html

Similar Messages

  • Java with xml

    Hi all,
    I am very new for java programming. I want to know how we retrieve data from xml file with the help of java programm. plz provide an example with code. Thanks

    http://java.sun.com/xml/tutorial_intro.html

  • HOWTO: Writing Out XML Query Results of Any Size in Java with XML SQL Utility

    A customer mailed me asking for an example of how to use our XML SQL Utility to write out query results for tons of query result rows.
    With tons of data, the getXMLDOM() and getXMLString() methods are not really appropriate due to the size.
    The XML SQL Utility offers a getXMLSAX() method that streams SAX2 events to report the data being queried. This is the approach we can use to handle data of any size.
    It dawned on me today that by putting together the XML SQL Utilities getXMLSAX() routine, and the oracle.xml.parser.v2.XSLSAXPrintDriver SAX2 ContentHandler, we can effectively stream out data of any length to an appropriate writer.
    Here's a code example to get the point across:
    package test;
    import java.io.BufferedOutputStream;
    import java.io.PrintWriter;
    import java.sql.Connection;
    import java.sql.Driver;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.util.Properties;
    import javax.xml.transform.OutputKeys;
    import oracle.jdbc.OracleDriver;
    import oracle.xml.parser.v2.XSLException;
    import oracle.xml.parser.v2.XSLOutput;
    import oracle.xml.parser.v2.XSLSAXPrintDriver;
    import oracle.xml.sql.query.OracleXMLQuery;
    public class Example  {
      private static final String QUERY = "select * from emp";
      public static void main(String[] args) throws Throwable  {
          Connection conn = getConnection();
          OracleXMLQuery q = new OracleXMLQuery(getConnection(),QUERY);
          // Any printwriter will do. Here's we're output to standard out.
          PrintWriter output = new PrintWriter(new BufferedOutputStream(System.out));
          // This is a SAX2 Content Handler used by the Oracle XSLT Engine
          // to serialize a stream of sax2 events as an XML document
          // We'll use it to serialize the sax2 events from the XML SQL Utility
          // out as an XML document.
          XSLSAXPrintDriver ch = new XSLSAXPrintDriver(output, outputOptions());  
          // This asks XML SQL Utility to fire sax events for the data
          // being fetched instead of creating DOM nodes or returning text.
          // By using the XSLSAXPrintDriver content handler, these events
          // get handled by writing them directly to the output stream
          q.getXMLSAX(ch);
          ch.flush();
          q.close();
          conn.close();     
      private static XSLOutput outputOptions() throws XSLException {
        XSLOutput x = new XSLOutput();
        Properties props = new Properties();
        props.put(OutputKeys.METHOD,"xml");
        props.put(OutputKeys.INDENT,"yes");  // Set to "no" for non-indented
        x.setProps(props);
        return x;
      public static Connection getConnection() throws SQLException {
        String username = "scott";
        String password = "tiger";
        String thinConn = "jdbc:oracle:thin:@localhost:1521:ORCL";
        Driver d = new OracleDriver();
        return DriverManager.getConnection(thinConn,username,password);
    }

    Hi Uber,
    This is a known issue that error occurs when running report "Count of instances of specific software registered with Add or Remove Programs" due to non-printable characters for XML. Based on internal research, the hotfix for this issue will be
    included in the System Center 2012 Configuration Manager Service Pack 1.
    As a workaround, you can remove the nonprintable character populated into the report parameter by referring to the following KB article:
    http://support.microsoft.com/KB/914159
    Hope this helps.
    Regards,
    Mike Yin
    Mike Yin
    TechNet Community Support

  • Create offline interactive forms using webdynpro java with XML data source

    Hi Gurus,
    I am having a scenario like below:
    Sales guy request for order list online from portal- Sytem receives the request and creat XML file- from xml file need to create a Offline interactive form-Sales guy fills it offline at customer site- uploads in portal -on submit xml has to be generated with captured data at customer site-Process to  ECC.
    So my questions are:
    How to create the offline interactive form  from XML?
    Once filled offline interactive form uploaded into portal how to create XML again from pdf ?
    Please give some idea on this as this is my first Offline interactive form using XML datasource.
    Thanks
    Ravi
    Edited by: Ravi Sunkara on Jul 27, 2010 5:25 PM

    Hi Otto,
    Sorry for replying lately. First of all  I did not get your suggestions as your are editing the same posting.
    Secondly we will be using WDJ. Actually in between SAP Portal and ECC we are having adobe LCES so we need to create Interactive form using XML only. Once it is filled again the form will be submitted to another application which is running on FLEX, which will process the order.
    if you can give me your personal id i can send you the detailed process
    Thanks
    Ravi

  • Java with xml please help me :(

    Hi,
    I need to design a Jva GUI interface where when an action is triggered the event will
    first look at some pattern(rules) defined in a XML file before been fired. I have no
    idea of how the communication is going to be established . I have never used xml in the past.
    Any help will be very very appreciated!
    Thank You

    Hello,
    Try to download Jaxp-1.1, U will get 3 JAR files - xalan.jar, crimson.jar and jaxp.jar.Set the classpath to this jar files. U will find the ZIP files in http://java.sun.com/xml/jaxp-1.1/docs/api, Iam not sure about the URl.Still need any help mail me to [email protected]
    Thanx

  • How can i use java with xml in netbean ide tell me step by step

    i am vivek kumar kanaujia from Kanpur

    No.
    Your client has provided you with a SMS gateway, and we don't know anything else about it. So we can't give you the code.
    Even if we could give you the code, we don't know what you want to do with it - what functionality do you want to expose to the users of the JSP?
    Even if we could knew what you were using and exactly what you wanted to do with it, why on earth would we want to write all your code for you?
    [Please read this link|http://www.catb.org/~esr/faqs/smart-questions.html]

  • Getting started with Java and XML

    Hi,
    Although I am pretty familiar with Java, I am a total newbie with using it to parse XML. I have been reading quite a few tutorials so am getting a good understanding of it and am thinking of using the DOM model for my purposes.
    What I haven't been able to find, however, is how I can actually get started with this. I have tried compiling a few examples and have been getting errors such as:
    xmltest.java package javax.xml.parsers does not exist
    xmltest.java package org.w3c.dom does not existetc etc...
    It looks like these packages don't come with J2SE. Can anyone confirm this? Do I need to download and install the Java Web Services Developer Pack to solve this problem?
    Finally, I know I will need an XML parser but have read that JDK 1.4 has it's own parser (Crimson). Is this adequate for parsing XML files or will I also need a parser such as Xerces?
    Thanks so much for any help!

    Hi DrClap,
    Thanks for the reply. I have JDK 1.4.1_02 installed on my server but the following error keeps coming up when I try to run my example:
    Exception in thread "main" java.lang.NoClassDefFoundError: org/w3c/dom/NodeAre there any further packages I need to download in order to run Java with XML? I have read some people install JAXP and XERCES... are these necessary for parsing an XML document or should J2SE 1.4.1 be sufficient?
    Thanks for your help!
    Jill

  • Help with XML - AS 3.0

    Hello everybody. I decided to start working with XML since it allows me to load assets externally and edit my applications later very easily without having to edit the fla file itself. So today I watched and read a few tutorials and now I'm trying to build an Event Scroll, all through XML and AS 3.0 code. Basically what I want is to have several events inside a movieclip which I will incorporate into a scroll pane when I'm done, for now I'll focus on extracting data from the XML file and parsing it with AS 3.0. The layout is simple: a thumbnail image on the left, and beside it on the right there is the title of the event, its date and some info about it and all of these should have a dark grey background while the text is in white. Each two events are 30 pixels apart and there are 5 events for now.
    Ok enough talking now let's get to the code:
    XML Code:
    <?xml version="1.0" encoding="utf-8"?>
    <EVENTSXML>
         <EVENT>
              <TITLE> Event 1</TITLE>
             <DATE>12/04/2009</DATE>
            <THUMB>thumb0.jpg</THUMB>
            <INFO> Some Text Goes Here </INFO>
        </EVENT>
         <EVENT>
               <TITLE>Event 2</TITLE>
             <DATE>03/02/2009</DATE>
            <THUMB>thumb1.jpg</THUMB>
            <INFO>Some Text Goes Here</INFO>
         </EVENT>
         <EVENT>
               <TITLE>Event 3</TITLE>
             <DATE>18/11/2008</DATE>
            <THUMB>thumb2.jpg</THUMB>
            <INFO>Some Text Goes Here</INFO>
         </EVENT>
         <EVENT>
               <TITLE>Event 4</TITLE>
             <DATE>10/09/2008</DATE>
            <THUMB>thumb3.jpg</THUMB>
            <INFO>Some Text Goes Here</INFO>
         </EVENT>
         <EVENT>
               <TITLE>Event 5</TITLE>
             <DATE>06/08/2008</DATE>
            <THUMB>thumb4.jpg</THUMB>
            <INFO>Some Text Goes Here</INFO>
         </EVENT>
    </EVENTSXML>
    Actionscript 3.0 Code:
    var myXML:XML;
    var req:URLRequest = new URLRequest("events.xml");
    var ldr:URLLoader = new URLLoader();
    ldr.load(req);
    ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, processXML);
    function processXML(e:Event):void
         myXML = new XML(e.target.data);
         buildEvents(myXML.EVENT);
    var eventScroll:MovieClip = new MovieClip();
    var padding:Number = 30;
    this.addChild(eventScroll);
    eventScroll.x = eventScroll.y = padding;
    function buildEvents(evnts:XMLList):void
         for(var i:uint = 0; i <evnts.length(); i++) {
              var eventData:MovieClip = new MovieClip();
              eventData.y = (20 + padding) * i;
              eventData.itemNum = i;
              eventData.title = evnts[i].TITLE;
              eventData.date = evnts[i].DATE;
              eventData.thumb = evnts[i].THUMB;
              eventData.info = evnts[i].INFO;
              // thumb container
              thisThumb:Sprite = new Sprite();
              var ldr:Loader = new Loader()
              var req:URLRequest = new URLRequest(eventData.thumb);
              ldr.load(req);
              thisThumb.addChild(ldr);
              eventData.addChild(thisThumb);
              eventScroll.addChild(eventData);
    now I am stuck there... the application is not done yet and when I publish the file I keep getting errors, these are the errors:
    1067: Implicit coercion of a value of type flash.display:Sprite to an unrelated type Class.
    Source: thisThumb:Sprite = new Sprite();
    1188: Illegal assignment to class Sprite.
    Source: thisThumb:Sprite = new Sprite();
    1120: Access of undefined property thisThumb.
    Source: thisThumb.addChild(ldr);
    1120: Access of undefined property thisThumb.
    Source: eventData.addChild(thisThumb);
    1119: Access of possibly undefined property contentLoaderInfo through a reference with static type flash.net:URLLoader.
    Source: ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, processXML);
    So where did I go wrong and how can I carry on with my code to finish my application?
    P.S: I do not want someone to do it for me, so in case someone decided to help me out, please comment and explain your code because this application is for learning porpuses in the first place... Thanks in advance!

    oh I've just noticed one little problem, in my info field, the text doesn't break and start a new line, it just keeps going horizontally although I've set it to multiline and gave it a width and height... so what shall I do to fix this problem? here's the code:
    var infoF:TextField = new TextField();
              infoF.text = eventData.info;
              infoF.x = 250;
              infoF.y = dateF.y + padding;
              infoF.multiline = true;
              infoF.width = 200;
              infoF.height = 100;
              addChild(infoF);

  • Merge LiveCycle Form with XML using JAVA

    Hello.
    I am trying to find out how to merge non-interactive form with XML (using JAVA) so the users can see the final output form with the data filled in.
    What are my choices..?
    So far, I have created the interactive forms as template using LiveCycle 8 and wrote ASP.NET code to extract data and store it in SQL database when the user fill out and submit the form.
    It works great but another agency wants to access the form as well.
    They told us that they will create the XML themselves from the database, so they just need to combine the form with XML to display it (non-interactive form).
    They want to use JAVA but I am not sure how to do that...
    Any suggestion?

    Assuming that you start with XML in an org.w3c.dom.Document that stores the XML data. Before you can merge it into a form, you have to convert it to a com.adobe.idp.Document object. TO convert a org.w3c.dom.Document to a com.adobe.idp.Document object -- use the following Java code:
    private Document convertDataSource(org.w3c.dom.Document myDOM)
    byte[] mybytes = null;
    try
    //Create a Java Transformer object
    TransformerFactory transFact = TransformerFactory.newInstance();
    Transformer transForm = transFact.newTransformer();
    //Create a Java ByteArrayOutputStream object
    ByteArrayOutputStream myOutStream = new ByteArrayOutputStream();
    //Create a Java Source object
    javax.xml.transform.dom.DOMSource myInput = new DOMSource(myDOM);
    //Create a Java Result object
    javax.xml.transform.stream.StreamResult myOutput = new StreamResult(myOutStream);
    //Populate the Java ByteArrayOutputStream object
    transForm.transform(myInput,myOutput);
    // Get the size of the ByteArrayOutputStream buffer
    int myByteSize = myOutStream.size();
    //Allocate myByteSize to the byte array
    mybytes = new byte[myByteSize];
    //Copy the content to the byte array
    mybytes = myOutStream.toByteArray();
    catch (Exception e) {
    System.out.println("The following exception occurred: "+e.getMessage());
    //Create a com.adobe.idp.Document object and copy the
    //contents of the byte array
    Document myDocument = new Document(mybytes);
    return myDocument;
    THen you can merge myDocument into the Form using renderPDFFOrm:
    FormsResult formOut = formsClient.renderPDFForm(
    formName, //formQuery
    myDocument, //inDataDoc
    pdfFormRenderSpec, //PDFFormRenderSpec
    uriValues, //urlSpec
    fileAttachments //attachments
    Hope this helps!

  • Help with Java to XML

    All I need to know is how to bold the tag <CompanyID> </CompanyID> OR the text within it (1001, in given sample).
    Here's a sample line of the data.txt file I'm working with:
    1001,"Fitzsimmons, Des Marteau, Beale and Nunn",109,"COD","Standard",,109,8/14/1998 8:50:02
    Thanks in advance!
    public class PracticeExerciseOne {
        public static void main(String [] args){
            DocumentBuilderFactory domFac = null;
            DocumentBuilder domBuild = null;
            //Element tags
            final String COMPANY = "Companies";
            final String COMPANY_ID = "CompanyID";
            //rest too long to post
            //Regex to be used for each field in the CSV file
            ArrayList<Pattern> patterns = new ArrayList<Pattern>();
            patterns.add(Pattern.compile("[0-9]+,"));
            patterns.add(Pattern.compile("\".+?\","));
            patterns.add(Pattern.compile("[0-9]+,"));
            patterns.add(Pattern.compile("\".+?\","));
            patterns.add(Pattern.compile("\".+?\","));
            patterns.add(Pattern.compile("[^,]*,"));
            patterns.add(Pattern.compile("[0-9]+,"));
            patterns.add(Pattern.compile("[^,]+ [^,]+"));
            //Store element tags in an array - too long to post
            try{
                //Build a new documet
                domFac = DocumentBuilderFactory.newInstance();
                domBuild = domFac.newDocumentBuilder();
                Document doc = domBuild.newDocument();
                //Create a new root element
                Element rootElement = doc.createElement(COMPANY);
                doc.appendChild(rootElement);
                //Read in the file
                BufferedReader in = new BufferedReader(new FileReader(new File("texts/data.txt")));
                BufferedWriter out = new BufferedWriter(new FileWriter(new File("texts/dataOut.xml")));
                int tempI;
                String line = in.readLine();
                //We will cut this string down after every element we take out of it
                String temp = line;
                String tempElement = "";
                while(line != null){
                    for(int i = 0; i < patterns.size(); i++){
                        //Matches a pattern to a field, starting with the first pattern
                        //Matchup should be 1st pattern = 1st field
                        Matcher matcher = patterns.get(i).matcher(temp);
                        if(matcher.find()){
                            //if we haven't reached the last field
                            if(i != 7){
                                //we want to get the index of the last comma within the matched group
                                tempI = matcher.group().lastIndexOf(',');
                                //create an element using the beginning of the given string and the last comma within that data
                                tempElement = temp.substring(0,tempI);
                            else{
                                //no comma in last field, so we just want to get the whole field
                                tempI = 0;
                                tempElement = temp.substring(0);
                            //if an empty element appears, add a space for tags to be placed correctly
                            if(tempElement.equals("")){
                                tempElement = " ";
                            //temp will be set to the remaining string, once we have taken the nth field out
                            temp = temp.substring(tempI+1);
                            //create an element with tags and append to document
                            Element em = doc.createElement(tags);
    em.appendChild(doc.createTextNode(tempElement));
    rootElement.appendChild(em);
    line = in.readLine();
    temp = line;
    //Transformer will create a new XML document using the Document we have built
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    DOMSource source = new DOMSource(doc);
    StreamResult result = new StreamResult(out);
    transformer.transform(source, result);
    out.close();
    in.close();
    catch(Exception e){
    System.err.println("Exception: " + e.getMessage());
    e.printStackTrace();

    maybe this can help You for now and future,
    in this site You can download a sample codes publish in this books - java fundamentals and advanced features.,
    in 2nd book, is a big chapter about java and xml. Please read this code, i will hope, this can help You.
    http://www.horstmann.com/corejava.html (for mod: this is not SPAM)

  • Java interface with xml communication

    Hello everybody,
    For a project i need to make a java interface with xml communication.
    For example ; from 1 laptop I press on a java button and then i need to get a text message on the other laptop.
    The java interface is already created now the xml code for communication.
    I hope someone can help me how to start with the xml code.
    Are there any templates that i can use?

    I need to use XML for this, cause it is in the
    assignment.As far as communication is concerned, it doesn't matter that you are sending XML. You can send any kind of data. So first find out how to send data, then send data which is XML.
    I only want to know if its possible to send data/text
    from 1 laptop (windowsxp prof) to the other laptop
    (also windows xp prof).Provided the other laptop is running a server that can receive that data.
    Maybe its easier if I send data to a specific IP
    address?Provided there is a server running at that IP address that can receive that data. You can use an IP address to connect to a server but that has nothing to do with sending the data.
    Its important that the communication between 2 system
    is in XML language.XML is not a programming language. XML is a format for storing data. You can certainly send XML-formatted data between two computers.
    So i hope u have a solution for my problem.The solution would be for you to learn how communication between two computers works in the real world. If you have an assignment that says you have to make communication work, surely there was something taught to you before about how to do it?

  • Accessing Java webservice (XML over http) via WCF or HTTP adapter with content-type and authorization HTTP headers with POST method

    Hi Team,
    I need to access Java web service which is simple service and accepts and returns XML over HTTP. No credentials are needed to access the service. We need to pass following two HTTP headers (Content-Type and Authorization) along with XML request message:
    <GetStatus> message is being constructed in the orchestration and URI is constant to access.
    Which adapter shall I use to get the response back? I tried using WCF-WSHttp with Security Mode = Transport, and different options of client credential types but every time, error returned stating:
    System.Net.WebException:
    The HTTP request is unauthorized with client authentication scheme 'Basic'. The
    authentication header received from the server was 'Basic realm='.
    Authentication failed for principal Basic. Message payload is of type:
    String 
    In Fiddler, request looks line following
    POST <https://URL/GetServiceReopnse HTTP/1.1
    Content-Type: application/xml
    Authorization: Basic cmVmU3RhdHN2Y19kgeRfsdfs=
    Host: <Server name>
    <GetStatus XMLNS="http://server.com/.....">
    <OrgId>232323</OrgId>
    <HubId>3232342323</HubId>
    </GetStatus>
    MMK-007

    First, you should not use the HTTP Adapter because it's been deprecated and replaced by WCF.
    Start with the WCF-Custom Adapter and select the customBinding.
    You should start with the textMessageEncoder and httpTransport and go from there.

  • How to work with xml in java ?

    Hello everybody. I am trying to read, write and modify xml file in java. But i don't know what is the best method for work with xml file ? Please give me some examples for read, write and modify it.
    Thanks in advance.

    >
    Hello everybody. I am trying to read, write and modify xml file in java. But i don't know what is the best method for work with xml file ?>'It depends'. I saw some discussions of XML parsing using different J2SE core XML APIs (the J2SE has a selection of ways to deal with XML) where one API was 20 times faster than the other.
    >
    ... Please give me some examples for read, write and modify it. >Please give me a ponie. ;-)
    You will probably need to do a lot of reading, as well as some experimentation, before you decide which XML API is best suited to the particular task you are facing.
    >
    Thanks in advance.>No worries.

  • Just Starting out with java packages

    Hello,
    I'm a beginner and I'm starting out with java packages.
    I wrote two simple .java files, one test program and one containing a simple class.
    Both files are compiling without errors but When I run the program I get an error NoClassDeffoundError.
    I use the import <package> statement And I think I'm using the CLASSPATH variable correctly.
    SET CLASSPATH=d:\nopol
    path for the .java containing the test class is:
    d:\nopol\utilities \myapp.
    In the test file I use "import utilities.myapp.*.
    I would be very happy if anyone could help me
    Thanks beforehand
    Nopol.

    The test file should be in d:\nopol, if it's not a part of your package utilities.myapp. Everything should be compiled from d:\nopol, the test class with "javac ClassName.java" and the class in the package with "javac utilities/myapp/ClassName.java".
    Your classpath seems fine for now, though. But yes, do add the period there, otherwise you could run into problems later.

  • How to start java applet with netbeans 6.1

    hey,
    I want to learn how to start java applet (with database) with netbeans.. I'm new to java...can you show me how can i start..if you have any doc about it can you send it to me..thank you..:)

    You really should be asking this NetBeans question at the NB site - these forums are for Java language topics, not NB support.
    [http://www.netbeans.org/kb/61/web/applets.html]
    Almost any NB question you have can be answered by either the NB web documentation or the NB program's Help.

Maybe you are looking for