aspose file tools*
The moose likes XML and Related Technologies and the fly likes XML details Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML details" Watch "XML details" New topic
Author

XML details

kademane guru
Greenhorn

Joined: Feb 20, 2007
Posts: 21
i am new to XML, i want to know how to read XML data in the java class?
without hard coding any things in java class. please help me out with some examples.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Moving to XML Forum.


Merrill
Consultant, Sima Solutions
kademane guru
Greenhorn

Joined: Feb 20, 2007
Posts: 21
Hi Merrill Higginson,
thanks and please send me some good example's URL regarding XML, then it will be easy form me to understand.

Thanks & Regards
Kademane guru
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41579
    
  54
Example code for using the DOM and SAX APIs to parse XML can be here.


Ping & DNS - my free Android networking tools app
kademane guru
Greenhorn

Joined: Feb 20, 2007
Posts: 21
Hi Ulf Dittmer,
thanks, just i am getting some idea on XML.
i have some problem in my project.

let me explain my project first
in my project i am hardcoding some values(tags with values) in one XML file that file i am showing below.

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

<Order>
<Manifest>
<Item>
<NAME>

<Name> Name</Name>
<Namelength>5</Namelength>
<Beginlength>10</Beginlength>
<Contains>10,20,30</Contains>
<Storequalification>nothing </Storequalification>
<Suffix>:</Suffix>

</NAME>

</Item>
</Manifest>
</Order>

i am doing my project using struts framework.

now i will tell my probelm.
1) I want read the tag names(i.e name,namelength,Beginlength,Contains) dynamically in struts action class, like if one array contains 10 values means we use for loop and we will print all the 10 values,like this i want to read only all the tag names which are in XML file.

2) I want read the tags like name,namelength,Beginlength,Contains etc.....
along with the values of the tags in the action class(struts action class),without hardcoding the tag names.

please provide the solution for this problem with some examples.


Thanks
Kademane guru
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41579
    
  54
You can use either DOM or SAX to do this. But if you want to avoid referring to element names, you will need to go by relative positions, which is an unstable thing to do. Why do you want to avoid using element names? If you don't want to hardcode them, read them from a property file instead.
kademane guru
Greenhorn

Joined: Feb 20, 2007
Posts: 21
Hi Ulf Dittmer sir,
thanks for reply. but i dont know, how to read the XML Tags from the proeprty file. please guide me how to do this ?

Thanks
Kademane guru
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41579
    
  54
You wouldn't read XML from a property file. What I suggested was a way to avoid hardcoding the names of the XML element in your XML parsing code. You would do that by reading their names from some property file. That file might look like this:



Then you don't have to refer to element "Name" in your code, but instead to the property "element.name". That way you can change the name of the element to (e.g.) "FirstName" later, and don't have to change the code; just the property file.
[ April 09, 2007: Message edited by: Ulf Dittmer ]
 
wood burning stoves
 
subject: XML details