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 name,surname, doamin name from mailid
How to extract the entire line with specific data from a Text in java?
Advertisements
How to extract values from SOAP Response message and insert in database
extract data from HTML
Extract frames from Video File
ModuleNotFoundError: No module named 'xmlr'
ModuleNotFoundError: No module named 'xmlx'
ModuleNotFoundError: No module named 'extract-from-url'
ModuleNotFoundError: No module named 'xmla'
ModuleNotFoundError: No module named 'xmla'
How can i extract email ids from xls/xlsx file in java?
extract content from javamail - JavaMail
How to Extract SQL schema into .xsl file
extract data from excel sheet to mysql
how to extract css properties using java?
how to code-updating some details n some details r unchanged
ModuleNotFoundError: No module named 'extract-specific-sites-from-msa'
ModuleNotFoundError: No module named 'extract-specific-sites-from-msa'
how to develop student details using springs
How to display gridview details to labels dynamically?
JSP to add details to a database from a HTML form.
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 equation
how to reach shirdi from delhi
how to read from dictionary c
how to retrieve data from database ?????/
how to retrieve data from database ?????/
how to retrieve data from database ?????/
how to retrieve data from database ?????/

Ads