How to extract details from XML?

Ads
 

How to extract details from XML?

View Answers

May 23, 2008 at 8:11 PM

Hi friend,

stocks.xml

<?xml version="1.0" encoding="UTF-8"?>

<portfolio>
<stock>
<symbol>code</symbol>
<name>Java Tutorial</name>
<price>70.0</price>
</stock>
<stock>
<symbol>code1</symbol>
<name>Online Tutorial Available</name>
<price>45.00</price>
</stock>
<stock>
<symbol>Roseindia</symbol>
<name>Allover world allow online Tutorial</name>
<price>124.10</price>
</stock>

</portfolio>

------------------------------------

genXML.jsp

<%@ page contentType="text/xml" %>

<?xml version="1.0" encoding="UTF-8"?>

<portfolio>
<stock>
<symbol>code</symbol>
<name>Java Tutorial</name>
<price>70.0</price>
</stock>
<stock>
<symbol>code1</symbol>
<name>Online Tutorial Available</name>
<price>45.00</price>
</stock>
<stock>
<symbol>Roseindia</symbol>
<name>Allover world allow online Tutorial</name>
<price>124.10</price>
</stock>
</portfolio>
-----------------------------------
stocks.jsp

<%@ page contentType="text/xml" %>

<jsp:useBean id="portfolio" class="PortfolioBean" />

<%
java.util.Iterator folio = portfolio.getPortfolio();
Stock stock = null;
%>
<?xml version="1.0" encoding="UTF-8"?>
<portfolio>
<% while (folio.hasNext()) { %>
<% stock = (Stock)folio.next(); %>
<stock>
<symbol><%= stock.getSymbol() %></symbol>
<name><%= stock.getName() %></name>
<price><%=stock.getPrice() %></price>
</stock>
<% } %>
</portfolio>
--------------------------------


May 23, 2008 at 8:13 PM

Stock.java


public class Stock implements java.io.Serializable {
private String symbol;
private String name;
private float price;

public Stock(String symbol, String name, float price) {
this.symbol = symbol;
this.name = name;
this.price = price;
}

public String getSymbol() {
return symbol;
}

public String getName() {
return name;
}

public float getPrice() {
return price;
}
}

-------------------------
PortfolioBean.java

import java.util.*;

public class PortfolioBean implements java.io.Serializable {
private Vector portfolio = new Vector();

public PortfolioBean() {
portfolio.addElement(new Stock("code", "Java", (float) 70.0));
portfolio.addElement(new Stock("code1", "Online Tutorial Available", (float) 45.00));
portfolio.addElement(new Stock("Roseindia", "Allover world allow online Tutorial",(float) 124.10));
}

public Iterator getPortfolio() {
return portfolio.iterator();
}
}

Ads









Related Tutorials/Questions & Answers:
How to extract details from XML? - JSP-Servlet
XMLA
Advertisements
How to extract name,surname, doamin name from mailid
How to extract the entire line with specific data from a Text in java?
extract data from HTML
How to extract values from SOAP Response message and insert in database
How to extract a specific line from a text file? - IoC
Extract frames from Video File
How can we extract string 'roseindia.net ' from a string http://[email protected] net using regular expression of php?
extract content from javamail - JavaMail
How to Extract SQL schema into .xsl file
How can i extract email ids from xls/xlsx file in java?
How to Extract row from table view using JSP Code - Java Beginners
extract data from excel sheet to mysql
how to extract css properties using java?
Java to extract info from .iCalendar files
how to access the details - Java Beginners
how to code-updating some details n some details r unchanged
how to develop student details using springs
JSP to add details to a database from a HTML form.
How to display gridview details to labels dynamically?
How to extract the values of a variable in a href statement. - Java Beginners
how to get the details of username&password of mysql - JDBC
how to retrive other details with an image - Swing AWT
extract equation
retrive the employee details with image from mysql database using jsp servlet
how to send email please give me details with code in jsp,servlet
HOW TO STORE MULTIPLE EMPLOYEE DETAILS TO XML FILE USING JSP?
Extract website
Extract Equation
Extract Equation

Ads