• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XML details

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to XML Forum.
 
kademane guru
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Example code for using the DOM and SAX APIs to parse XML can be here.
 
kademane guru
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
I wasn't selected to go to mars. This tiny ad got in ahead of me:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic