New to XML!!!  Help!!!

Hi Everybody,
I am kind of new to XML... I would like to create a XML file from ResultSet.
Can some some please show me a simple example on how this can be done.
Thanks in advance.

Here's a quick and dirty example:
public String toXML( String sql )
throws SQLException {
StringBuffer xml = new StringBuffer( 2048 );
xml.append( "<SQLResults>" );
int row = 0;
Connection connection = getConnection();
try {
Statement statement = connection.createStatement();
try {
ResultSet resultSet = statement.executeQuery( sql );
try {
ResultSetMetaData rsmd = resultSet.getMetaData();
while ( resultSet.next() ) {
row++;
xml.append( "<Row Count=\"" );
xml.append( row );
xml.append( "\">" );
for ( int i = 1; i <= rsmd.getColumnCount(); i++ ) {
String colName = rsmd.getColumnName( i );
String value = resultSet.getString( i );
xml.append( "<" + colName + ">" );
xml.append( ( value == null ) ? "" : value );
xml.append( "</" + colName + ">" );
xml.append( "</Row>" );
finally {
resultSet.close();
finally {
statement.close();
finally {
connection.close();
xml.append( "</SQLResults>" );
return xml.toString();
You'll need to check the column names and values returned for invalid XML characters (for example, an '&' as part of a value -- "Smith & Jones ").

Similar Messages

  • New to XML need help!!!!!!!!!!11

    Hello
    I am new to XML. I want to generate HTML using XML + XSL.
    I got following class that does the same.
    But it stores generated output in file, while I need in String or StringBuffer as a result.
    Is there any utilities or way to achieve the same?
    Reg,
    Chetan
    import java.io.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    import javax.xml.parsers.*;
    import javax.xml.transform.*;
    import javax.xml.transform.dom.*;
    import javax.xml.transform.stream.*;
    public class BasicXsl {
         public static void xsl(String inFilename, String outFilename, String xslFilename) {
              try {
                   TransformerFactory factory = TransformerFactory.newInstance();
                   Templates template = factory.newTemplates(new StreamSource(
                        new FileInputStream(xslFilename)));
                   Transformer xformer = template.newTransformer();
                   Source source = new StreamSource(new FileInputStream(inFilename));
                   Result result = new StreamResult(new FileOutputStream(outFilename));
                   xformer.transform(source, result);
              } catch (FileNotFoundException e) {
              } catch (TransformerConfigurationException e) {
              } catch (TransformerException e) {
                   SourceLocator locator = e.getLocator();
                   int col = locator.getColumnNumber();
                   int line = locator.getLineNumber();
                   String publicId = locator.getPublicId();
                   String systemId = locator.getSystemId();
         public static void main(String args[]) {
              BasicXsl x = new BasicXsl();
              x.xsl("screen.xml", "demo", "screen.xsl");
    }

    But it stores generated output in file, Result result = new StreamResult(new FileOutputStream(outFilename));>while I need in String or StringBuffer as a result. Writer writer = new StringWriter();Result result = new StreamResult(writer);
    return writer.toString(); Pete

  • Xml help with project?

    Hey guys, Java newbie here, was wondering if anyone could point me in the right direction.
    so my co-worker gave me a folder with a bunch of .tif image files and one .xml file. I'm supposed to write Java code to copy a folder with the same name as the folder he gave me, and copy the .xml file into that folder. so the end result is that we have the original folder w/ the .tif files and .xml file, and one copy folder with the same name with a copy of the .xml file in it.
    this is the code that i have so far:
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import java.io.File;
    public class FileCopy{
    public static void copyFile(Document source, Document target)
    Node node = target.importNode(source.getDocumentElement(), true);
    target.getDocumentElement().appendChild(node);
    static void report(boolean b){
         System.out.println(b ? "success" : "failure");
    public static void main(String args[]){
         boolean status;
         status = new File("/project1").mkdirs();
         report(status);
    some of my questions are:
    A) how do i copy the exact name of the folder / .xml file?
    B) how do i even create a new blank .xml file for which i can use copyFile to copy over? (note it needs both a source and a target)
    C) how do i find the .xml file in the folder in which he gave me?
    Any help is appreciated

    rzhang10 wrote:
    Okay, but how do I ensure that the file I copied will be a .xml file?Mixing up of tenses leading to ambiguity! Bottom line: if it was XML, and you copy it, it will be XML.
    here is a copyFile function I found on the web:
    public static void copyFile(File in, File out) throws IOException{
              FileChannel inChannel = new FileInputStream(in).getChannel();
              FileChannel outChannel = new FileOutputStream(out).getChannel();
              try{
                   inChannel.transferTo(0 , inChannel.size(), outChannel);
              catch(IOException e){
                   throw e;
              finally{
                   if(inChannel != null) inChannel.close();
                   if(outChannel != null) outChannel.close();
    are you saying that this code would be sufficient to copy an .xml file? everytime I've tried it, it reproduces a .txt file.An XML file is a text file.

  • New to xml, simple communication

    Hi there
    I'm new to xml and as a uni project i've been asked to get two independent programs to communicate via xml. Specifically i am looking to exchange data contained in the databases maintained by each program.
    I would be very gratefull for any help or direction towards implementing this client/server based problem
    many thanks
    Joseph

    So, is your question "How do I read and write XML files" or is it "How do I communicate between two systems"? Either of those are really too vague to be answered on a forum, but the combination of both is hopeless.

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

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

  • I keep being asked to update my Safari but when I do a Software update it scans but never gives me a list and just says no new updates. Help please!

    I keep being asked to update my Safari but when I do a Software update it scans but never gives me a list and just says no new updates. Help please!

    There are no updates to either OS 10.5.8 or Safari 5.0.6.
    If you need a later version of Safari you must first upgrade your operating system to a later version of OS X.

  • New to XML and Oracle

    Just trying to clarify some issues as I try and learn about XML, and specifically how it integrates into the DB.
    1 - Is there a way with Oracle tools for me to get an XSD of an existing 9i relational schema? We are not currently using the XML DB, but our middleware developers would like to have an up to date XSD to use for their internal mapping.
    2 - Is there any way that I can keep that XSD up-to-date automatically, so I get a new one whenever the schema gets updated?
    3 - If I wanted to investigate storing XML docs within the DB in native XML format, I need to have an XML DB, correct? Is this DB construct maintained seperatelly from my "normal" relational schema? or are they kept in sync by Oracle?
    I know these may all be real basic questions, but as I said, I'm new to XML and Oracle. I am reading as much as I can, but there are a lot of docs out there.
    Thanks,
    Mike

    Hi
    1. On my opinion such a tool doesn't exists. Some parts can be implemented elsewhere, but not as described by you... e.g. with XSU if you specify the parameter "withschema" the XSD of the executed statement is generated. Another example is to use DBMS_METADATA to dump the data dictionary in XML (but not XSD, of course you could write your own XSLT to do this transformation...).
    2. -
    3. If you use XSD-based tables the XSD and the relational model are stored separately in the data dictionary. Therefore if you change the XSD you have to drop/create the XSD-based table... no schema evolution yet.
    Chris

  • How to create new Custom XML Report without using Form Builder

    Hi,
    What are the steps to create new Custom XML Report without using Report Builder ?
    Thanks and Regards,
    Abhi

    Hi,
    Steps we now follow
    1)Create Data Model in Reports Builder
    2)Create xml
    3)Insert xml in Publisher to build Fomat
    4)FTp rdf
    5)Create Data Definition and Template
    6)Create executable and Concurrent Program
    Is there any way we can build reports without use of Report Builder ? By writing PL SQL Package for Before Report and After Report etc ...
    Thanks and Regards,
    Abhijit Rode

  • My dad and I have shared an iTunes account for years and I just created a new apple id but I have no Idea how to get all those purchases to this new account. Help please?

    My dad and I have shared an iTunes account for years and I just created a new apple id but I have no Idea how to get all those purchases to this new account. Help please?

    The old Apple ID (presumably your dads) owns those songs and your new Apple ID does not.  However, your dad can authorize your iD to use the songs by going to Store > Authorize This Computer from your iTunes menu and entering his Apple ID and password.

  • Does anyone have any new recommendations to help iTunes recognize that my 128 iPhone and 128 iPad aren't 16 GB models?

    I have suffered from this problem for years, but since upgrading to 128 iOS devices in September, the mysterious iTunes/iOS hidden data disease has gotten intolerable. Here's the deal:
    I use my iPhone and iPad mostly for media consumption. I don't have a ton of apps. I have lots of videos, music through iTunes Match, and a few pictures. I'm one of those dinosaurs who doesn't use the cloud but downloads it, stores it, and syncs it via USB frequently (which I would bet is the root of my problem). Although I have a large capacity devices, I sync almost daily. And each time I sync, my displayed free space and the space iTunes allows me to use differs more and more. Old fixes used to involve such things as restoring the devices, turning off automatic syncing, turning off photo syncing, turning off other syncing apps, etc. And these things were temporary fixes.
    Let me give you an example of what I mean by temporary. It has been exactly eight days since I last restored my iPad to brand spanking new, retaining nothing. In those eight days and approximately eight or nine manual USB syncs, each with an average of 60 GB transferred, I mysteriously have managed to lose 40 GB. This afternoon during my most recent sync, iTunes showed 86.3 GB free. However, as usual, it wouldn't sync anything close to that. By the time I had whittled my selections down to an acceptable amount, it still showed I had 47.2 GB free both in iTunes and in Settings on the iPad. Yet when tested it by trying to sync a 50 MB app, it said there was not enough available space. In days past, problems like this would take weeks or maybe even months to accumulate. And the culprit would usually be the "Other" category. When that happened, the remedies I described would help. This new beast is something else, though. Like I said, this took only eight days.
    I finally decided to post something, though, after I reset my iPhone to factory settings this evening. When I was syncing the initial apps and videos, it would not let me sync more than 30 GB of material. I don't know what to do, guys. I bought the maximum capacity devices because I like my HD content. Does anyone know what I'm doing wrong? If you say I just need to sync less, (1), Apple needs to get its act together, and (2) It might sound crazy, but I can probably only push it to 2 days, so I'd only be postponing my problems a few days.
    If anyone can help, I would appreciate it. Forgive me if this has been addressed elsewhere. I have spent time searching, but all I found was the answers I have already tried numerous times.

    Emily Sitton wrote:
    I got my baby iPhone the day it came out. Seriously, I love it. I'm not really mad about the price drop, a little frusterated, but I knew what I was getting myself into when I purchased mine so early. But, now that I know there are ringtones in the future, I just can't wait.
    So basically, does anyone know for sure when we will be able to get the ringtones? And what about iTunes on the iPhone, when will that pop up? I'm sure these questions have been posted already, but I just can't seem to find a sure answer.
    I'm worried that it is just my iPhone/computer that can't find the update to get all the cool new feautres, any help?
    thanks in advance!
    Sit tight, once it's out you WILL KNOW. The Apple Discussions will be bombed!
    William

  • About a month ago my wifi switch greyed out. I went through all the trouble shooting and ended up going to the Genius Bar and got a new iPhone 4S. Now the switch greyed out on the new one.. help!

    About a month ago my wifi switch greyed out. I went through all the trouble shooting and ended up going to the Genius Bar and got a new iPhone 4S. Now the switch greyed out on the new one.. help!
    I've had my new one for less than 3 weeks. What gives? I'm loosing faith in apple

    no body?

  • TS1368 I can't download anything from the app store or iTunes today on my ipad2. Doesn't matter whether it is a previously purchased app or a new one. Help???

    I havent had any problems with my iPad2 until today. I cannot download anything from the app store or iTunes. Doesn't matter if it's a previously purchased app or a new one. Help???
    I just get a message--- after a long wait where the app icon says "waiting" that I can't connect to iTunes.
    Wifi signal is strong. All bars.

    Try these articles:
    Can't connect to the iTunes Store
    http://support.apple.com/kb/TS1368
    iOS: Troubleshooting Wi-Fi networks and connections
    http://support.apple.com/kb/TS1398
    If this will not work, best to contact phone support.
    http://support.apple.com/kb/HE57

  • I am getting the message "The windows installer Service could not be accessed when trying to install Itunes on my new computer, any help would be appreciated.

    I am getting the message "The windows installer Service could not be accessed when trying to install Itunes on my new computer, any help would be appreciated.

    Hey there Frank0619,
    If you have not been able to install iTunes because the Windows Installer service is not available, I would recommend the troubleshooting in the following troubleshooting to help.
    Issues installing iTunes for Windows
    These in particular: 
    Make sure you have an administrator account.
    To install iTunes, you'll need to log in to your computer with an administrator password. If you're not sure if you have an administrator account, read Windows 7: How do I log on as an administrator? You could also refer to your computer's help system, contact your IT department, or visit support.microsoft.com for assistance.
    Install the latest Microsoft Windows updates.
    To download the latest updates, visit the Microsoft Windows Update website. iTunes for Windows requires Windows XP, Windows Vista, Windows 7, or Windows 8 with the latest Service Pack installed. If you can’t install the updates, refer to your computer's help system, contact your IT department, or visit support.microsoft.com for assistance.
    Download the latest version of iTunes.
    The latest version of iTunes can be downloaded at http://www.apple.com/itunes/download/.
    Disable conflicting software.
    Some Windows background processes can cause issues for other programs and processes. These conflicts can prevent applications, such as iTunes, from installing. Disable conflicting processes by starting your computer using MSConfig: 
    Using Msconfig to troubleshoot conflicts in Windows XP
    Using Msconfig to troubleshoot conflicts in Windows Vista, Windows 7, and Windows 8
    Some security software made by other companies can't be disabled using MSConfig. If you've installed security software and you're having issues installing iTunes or QuickTime for Windows, you might need to disable or uninstall security software to resolve installation issues.
    Restart your computer.
    Install iTunes.
    Thank you for using Apple Support Communities.
    All the best,
    Sterling

  • Brand new Mac user help please! How do you connect a 17" monitor to the MacBook? I have the monitor plugged into the Mac, but the F8 that I am used to with PC does not work. Please help. Thanks.

    Brand new Mac user help please! How do you connect a 17" monitor to the MacBook? I have the monitor plugged into the Mac, but the F8 that I am used to with PC does not work. Please help. I am getting lots of spelling errors as the MacBook laptop screen is too small. Thank you so much! .

    Contentmom6 wrote:
    Brand new Mac user help please! How do you connect a 17" monitor to the MacBook? I have the monitor plugged into the Mac, but the F8 that I am used to with PC does not work.
    Normally, you just connect the monitor to the MacBook using a VGA adaptor that you can buy from an Apple Store.  Now try System Preferences > Displays > Detect Displays.  You should now be able to select a display mode for the monitor.  If it still doesn't work, then I'd check that everything is properly connected.  I've had problems with colours disappearing due to a faulty connection in the VGA adaptor.
    Bob

Maybe you are looking for

  • Find the relationship between tables where the constraint type is 'R'

    Hello, I am trying to find an answer of the following question: How to query the user_constraints view (probably some more views should be involved here) in order to get information about the table name, the column (or columns) that is (are) a foreig

  • Dial with country code as prefix won't work

    Hey The Sony Z1 latest ROM have the issue, it can't dial when the phone number don't have + before the country code.

  • How to get support for research work from oracle?

    sir i want to undergo a research from a univ at my city on db security and cryptography.i may require some document and psudo code of certain algorithim.how to get those from oracle? regards

  • Determining what site(s) has not refreshed from master database

    Is there a way to determine what sites have refreshed at the master level ? Is there a system table or v$view that contains this information ? I have a master read-only snapshot setup with an oracle 8i master and oracle 8.04 snapshot sites(54). I wan

  • CS6 Windows 8 install problem

    I have created a package using AAMEE tool for CS6. When I try to install the msi it fails and when I check the log file it complains about a Sonic driver. CS6 will install fine from the DVD's. Machine is running windows 8 pro.