java and xml

Discussions

Web tier: servlets, JSP, Web frameworks: java and xml

  1. java and xml (10 messages)

    hi friends,
              my questions are regarding xml with java
    1)i want to populate values from data base table to an xml file.how to do it.

    2)is there any possiblity to update the xml file whenever the table is updated

    3)i want to query that xml file..
      for example..i have an xml file in the following structure
    <details>
      <player>
         <pid>0001</pid>
         <pname>xxxx</pname>
      </player>
      <player>
         <pid>0001</pid>
         <pname>xxxx</pname>
      </player>
    </details>
       so if i give the pid value in the html page it should ind the related name in xml ile and displayed in the html page..

    dear friends please help me

    karthik

    Threaded Messages (10)

  2. java and xml[ Go to top ]



    sorry small mistake in that question..read it now


    hi friends,
              my questions are regarding xml with java


    1)i want to populate values from data base table to an xml file.how to do it.

    2)is there any possiblity to update the xml file whenever the table is updated

    3)i want to query that xml file.. for example..i have an xml file in the following structure

     
    <details>

      <player>
         <pid>0001</pid>
         <pname>xxxx</pname>
      </player>

      <player>
         <pid>0002</pid>
         <pname>yyyy</pname>
      </player>

    </details>


       so if i give the pid value in the html page it should ind the related name in xml ile and displayed in the html page..

    dear friends please help me

    karthik
  3. java and xml[ Go to top ]

    Hi
     This is one of making a XML file from the data in the databse.

    FileOutputStream outStrem = new FileOutputStream("Player.xml");
    PrintStream p = new PrintStream(outStream);
    String xmlreader="<?xml version='1.0' ?><details>";

    while(rs.next())
    {
     xmlreader += "<pid>"+ rs.getInt("pid") +"</pid>":
     xmlreader "<player><pname>"+ .getString"pname")+ "</pname>
                  </player>";
    }

    xmlreader += "</details>";

    p.print(xmlreader);


    In order to retrive data from xml file or search a xml file u need to impelement java SAX or org.xml.sax

    Hope this works
    Bye
    Asad

  4. java and xml[ Go to top ]

    XPath provides a simple set of query (selection) expressions.

    In xpath you could select the node(s) you want by saying:
    //player[pid='0001']

    This will select any player node (in the current tree) that has a pid child element with the text '0001'.

    dom4j (www.dom4j.org) support xpath.

    "Node.selectNodes(String xpathExpression)
     selectNodes evaluates an XPath expression and returns the result as a List of Node instances or String instances depending on the XPath expression."

    Hope this helps...
    Later,
    skot
  5. java and xml[ Go to top ]

    hello guys,
               thx for your help..let me try it..can u please tell me some useful sites for that(regarding xpath etc)..

    thanks again
    karthik
  6. java and xml[ Go to top ]

    Try this one:
    http://www.zvon.org/

    There's a lot of tutorials and references in it.
    Direct link to XPath tutorial:
    http://www.zvon.org/xxl/XPathTutorial/General/examples.html

    XPath is closely connected with XSLT, so any documents covering XSL are likely to include XPath examples (try XSL links at Zvon.org)

    Regards

    Wojtek
  7. java and xml[ Go to top ]

    Hi friend,
         Thanks for ur reply..i saw the site u have given..it was good..but im not able to find a good xpath tutorial with java..can anyone send me an example files or can anyone tell me some sites for java and xpath

    thank you
  8. java and xml[ Go to top ]

    Using XPath with Java requires XSL translator package. You can get one from xml.apache.org (it's called Xalan). There are some examples attached to it. Using XPath in Java is starightforward. All you must write is XSL transformation. Check Xalan examples.

    Regards

    Wojtek
  9. java and xml[ Go to top ]

    hi wojtek,
            thax for your help again..i havent tried xalan..before that i want to query xml thru client side itself using xsl and (or) java script..here is a file i found in net..here they compared artist name and display correspondin details..is there anyway to pass that dynamicallyusing javascript or something else without using java..ie..i want to pass that artist value from html..how to i get the value from html page and substitue in that condition...

    the xsl file is

    <?xml version='1.0'?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    <xsl:template match="/">
     <html>
     <body>
      <table border="2" bgcolor="yellow">
       <tr>
        <th>Title</th>
        <th>Artist</th>
       </tr>
       <xsl:for-each select="CATALOG/CD[ARTIST='Bob Dylan']"> //here i want to pass the values dynamically
       <tr>
        <td><xsl:value-of select="TITLE"/></td>
        <td><xsl:value-of select="ARTIST"/></td>
       </tr>
       </xsl:for-each>
      </table>
     </body>
     </html>
    </xsl:template>
    </xsl:stylesheet>

    hope u help me again

    karthik

  10. java and xml[ Go to top ]

    The only way you can do it is to use Internet Explorer XSL translation capabilities (I don't know if Netscape has it's equivalent). IE reads XML files (to translate it with suitable XSL, you should include the following line into the XML):

    <?xml-stylesheet type="text/xsl" href="myXSL.xsl"?>

    This should work fine, but I suggest to use server-side translations. They're browser independent.
  11. java and xml[ Go to top ]

    hi wojtek,
        im aware of using xml with xsl..but i wanna know how to pass that values(i specified abt it in my last question)
    dynamically to xsl..
    if u know pls help