File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultsSet to XML

 
jonas okwara
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello All, I have spent several days trying to get this code to output to an xml format. Please I will appreciate if i am pointed to what i am doing wrong. The output works but it is not formatted in xml.

My code is below:

Thank You
Jonas

while (rs.next()) {
String firstname = rs.getString(1);
String lastname = rs.getString(2);
writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
writer.println("<employeeInfo>");
writer.println("<contacts>");
writer.println("<FirstName>");
writer.println(firstname);
writer.println("</FirstName>");
writer.println("<LastName>");
writer.println(lastname);
writer.println("</LastName>");
writer.println("</contacts>");
writer.println("</employeeInfo>");[/b]
 
Paul Clapham
Sheriff
Pie
Posts: 20188
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That doesn't look too bad to me. What makes you think the output isn't well-formed XML?

(I can see several potential problems but I don't see any point in guessing when you could just provide a description of the problem.)
 
jonas okwara
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Like I said there were no errors but I see something like this:

jonas smith sandra smith john tandi micheal lowell

I expect to see this:
<employee>
<contact>
<firstname>jonas</firstname>
<lastname>smith</lastname>
</contact>
</employee>

etc.
 
Paul Clapham
Sheriff
Pie
Posts: 20188
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say "see", are you perhaps using a browser to display that document as HTML? Try "seeing" it in some more usual way, like outputting it to a file or the console.
 
jonas okwara
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Yes I am using a browser
 
Paul Clapham
Sheriff
Pie
Posts: 20188
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well there you go then. The browser assumes it's HTML, and any tags which aren't HTML it just ignores them.
 
jonas okwara
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone. I was able to figure it out with the following code:

writer.println("<candidateInfo>");

while (rs.next()) {

writer.println("Firstname" + rs.getString(1) + "Firstname\n");
writer.println("Lastname" + rs.getString(2) + Lastname\n");
writer.println("Level" + rs.getString(3) + "Level\n");
writer.println("Score" + rs.getString(4) + "Score\n");
}

writer.println("candidateInfo");

This is now my Output:

<employeeInfo>
<Firstname>Chiemeka</Firstname>
<Lastname>Okwara</Lastname>
<Phone>2402067545</Phone>
<State>MD</State>
<Firstname>Adadadi</Firstname>
<Lastname>Okwara</Lastname>
<Phone>2402067545</Phone>
<State>MD</State>
<Firstname>Nneoma</Firstname>
<Lastname>Olisa</Lastname>
<Phone>2402067545</Phone>
<State>MD</State>
</employeeInfo>

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic