File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Representing an xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Representing an xml" Watch "Representing an xml" New topic
Author

Representing an xml

Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
Hi,
I have an XML file that looks like this
<?xml version="1.0"?>
<RESPONSE>
<FEATURES>
<FEATURE>
<FIELDS CUST_ID="4" NAME="Customer" #SHAPE#="[Geometry]" #ID#="3" />
<FIELDS CUST_ID="5" NAME="Customer1" #SHAPE#="[Geometry]" #ID#="3" />
<FIELDS CUST_ID="6" NAME="Customer2" #SHAPE#="[Geometry]" #ID#="3" />
<FIELDS CUST_ID="7" NAME="Customer3" #SHAPE#="[Geometry]" #ID#="3" />
</FEATURE>
</RESPONSE>
How do I extract the fields from this XML file ?
How can I represent the data in this in an HTML format ?
ie,
CUST_ID Name SHAPE ID
and the values one by one inside each colums
How will I do it ?
Thanks,
Maya
Ganesh Ram
Ranch Hand

Joined: Jul 20, 2001
Posts: 33
To extract values out of this XML doc, you would have to use a XML DOM Parser. There are many parsers available like xml4j from IBM. These parsers would read the inputstream and give you a Document object back.
From this Document object you can extract the Elements, attributes etc .. using the API.
From representing this XML doc as a HTML doc, you will have to create a XSL.
Microsoft may have tutorials on how to write XSL's.
If the XML doc refers to a XSL and if you use IE to read the XML, it would automatically display the intended HTML.
With Netscape, you would have to the transformation server side.
Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
Ganesh,
Thanks for the response.
My boss wants me to do this thing in Javascript.
Do you know how to use Javascript to extract the values ?
Any suggestion is welcome
Maya
L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
Hi,
I think you can use DOM Parsing. Since you wanted to do it using Javascript, I think you can use client side Paring. I.E use Microsoft's XMLDOM parser for XSLT on Client Side.
I will try to give you an example after working on it.
you can refer www.w3schools.com/xsl .
Thanks.

------------------
L Goundalkar
lggoundalkar@hotmail.com
Sun Certified Programmer for Java 2 Platform


SCJP, SCWCD
Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
Hi Goundalkar,
Thanks for offering the help.
Can you Please send the code to google_n@hotmail.com ?
Also, if I use the MSXML DOM parser, then how will I make it working in Netscape ?
Thanks,
Maya
Sham Jowsaki
Ranch Hand

Joined: May 22, 2001
Posts: 146
Hi,
Find below the sample coding of client side XML transformation
Transforming it on the Client (Using Javascript)
Here is the simple source code needed to transform the XML file to HTML on the client (try it yourself):
<html>
<body>
<script language="javascript">
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("cd_catalog.xml")
// Load the XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("cd_catalog_sort.xsl")
// Transform
document.write(xml.transformNode(xsl))
</script>
</body>
</html>

Cheers
Jowsaki
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Representing an xml