Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parsing data from xml files

Status
Not open for further replies.

omerdurdu

Programmer
Jul 21, 2001
72
TR
I am new in Java programming. I have a question about parsing data from an xml file. That can be maybe using string functions or some other functions.
here is the xml file I have:

<?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?>
<metadata>
<idinfo>
<citation>
<citeinfo>
<origin>National Park Service Geologic Resources Inventory (GRI) program.</origin>
<pubdate>Unpublished Material</pubdate>
<title>Geologic Units and Contacts of Natural Bridges National Monument and Vicinity, Utah (NPS, GRI, NABR, NABRGLG)</title>
<edition>1st</edition>
<geoform>vector digital data</geoform>
<lworkcit>
<citeinfo>
<origin>National Park Service Geologic Resources Inventory (GRI) program.</origin>
<pubdate>20010301</pubdate>
<title>Geologic Map of Natural Bridges National Monument and Vicinity, Utah</title>
</citeinfo>
</lworkcit>
</citeinfo>
</citation>
<descript>
<abstract>The Geologic Units and Contacts of Natural Bridges National Monument and Vicinity, Utah data (NABRGLG) consists of area (polygon) geologic units and the contacts/map boundary that defines those areas (polygons). The data were completed as a component of the Geologic Resources Inventory (GRI), a co-operative program between the Natural Resources Information Division (NRID) Inventory and Monitoring Program (IM) and the Geologic Resources Division (GRD) of the National Park Service (NPS). The spatial data (coverage/theme) was produced from an .E00 coverage with area geologic units and contact arcs. The &apos;new&apos; coverage/theme (NABRGLG/NABRGLGA) was attributed as per the NPS GIS-Geology Data Model. An indexed ArcInfo .E00 (export) coverage file and an ArcView 3.2 .SHP theme were then also created. The coverage/theme is within the area of interest of Natural Bridges National Monument. The coverage/theme is in NAD83, UTM Zone 12N.</abstract>
<purpose>Data intended to assist NPS personnel in the protection and management of Natural Bridges National Monument.</purpose>
<supplinf>The Geologic Units and Contacts of Natural Bridges National Monument and Vicinity, Utah coverage/theme (NABRGLG/NABRGLGA) is a component of the Geologic Map of Natural Bridges National Monument and Vicinity, Utah. Other coverages/themes that comprise the Geologic Map of Natural Bridges National Monument and Vicinity, Utah include: NABRATD (geologic attitude observation points), NABRSEC (geologic cross section lines) and NABRUPF (unique geologic point features). Two accessory data tables, NABRGLG1 (accessory geologic unit data) and NABRMAP (source map information), are also considered map components.</supplinf>
</descript>
<timeperd>
<timeinfo>
<sngdate>
<caldate>20010301</caldate>
<time>Unknown</time>
</sngdate>
</timeinfo>
<current>ground condition</current>
</timeperd>
<status>
<progress>Complete</progress>
<update>None planned</update>
</status>
<keywords>
<theme>
<themekt>none</themekt>
<themekey>Natural Bridges National Monument</themekey>
<themekey>Utah</themekey>
<themekey>geology</themekey>
<themekey>geologic units</themekey>
<themekey>geologic contacts</themekey>
<themekey>GLG</themekey>
<themekey>NABRGLG</themekey>
<themekey>National Park Service</themekey>
<themekey>NPS</themekey>
<themekey>Geologic Resources Inventory</themekey>
<themekey>GRI</themekey>
</theme>
<place>
<placekt>none</placekt>
<placekey>Natural Bridges National Monument</placekey>
<placekey>Utah</placekey>
<placekey>United States</placekey>
<placekey>US</placekey>
<placekey>USA</placekey>
<placekey>North America</placekey>
<placekey>NABR</placekey>
</place>
</keywords>
<accconst>None</accconst>
<useconst>Not for use at scale greater than 1:24,000.</useconst>
<ptcontac>
<cntinfo>
<cntperp>
<cntper>Stephanie O&apos;Meara</cntper>
<cntorg>Colorado State University</cntorg>
</cntperp>
<cntpos>Research Associate, Geologist/GIS Specialist</cntpos>
<cntaddr>
<addrtype>mailing and physical address</addrtype>
<address>1201 Oak Ridge Drive, Suite 200</address>
<city>Fort Collins</city>
<state>Colorado</state>
<postal>80525</postal>
<country>USA</country>
</cntaddr>
<cntvoice>(970) 225-3584</cntvoice>
<cntfax>(970) 225-3585</cntfax>
<cntemail>Stephanie_O&apos;Meara@nps.gov</cntemail>
<hours>9:00 a.m. to 5:00 p.m. (MST), Monday - Friday</hours>
</cntinfo>
</ptcontac>
<datacred>Jaqueline E. Huntoon (Michigan Technological University).</datacred>
<native>Windows NT Version 4.0 (Build 1381) Service Pack 6; ESRI ArcInfo 8.1.0.415</native>
</idinfo>
</metadata>

I would like to take the data out between the tags. Is there anyway i can do it with string functions. Can someone help me. thanks.

 
You could do it with string functions relatively easily if the format is always going to be the same. Try creating a method that will accept a tagname (without the brackets) and returns a string. Then just grab the substring between &quot;<&quot;+tagname+&quot;>&quot; and &quot;</&quot;+tagname+&quot;>&quot;. If you write the function to do it than you could simple set variables = yourFunction(&quot;origin&quot;) (for example) to get the origin information (or any other tag)>

It may be better, however, to download the XML parsers from Sun or Jakarta. They are free additional libraries that will give you a great deal more functionality. You will be able to loop through the entire document object by either indexes or tag names, read it all at once or as a stream...the list goes on. It is a little much to begin with but there are a lot of good examples out there.
As an additional tool, you may want to join the XML forum here if you decide to start working with the XML parsers (xalan, crimson, etc), most of the XML parsers work almost exactly the same except for language formatting.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Tarwn,
Thanks for replay. Can you show me that in the code
I am pretty new in this:
Here is a part of xml file:
<metadata>
<idinfo>
<citation>
<citeinfo>
<origin>National Park Service Geologic Resources Inventory (GRI) program.</origin>
<pubdate>Unpublished Material</pubdate>
<title>Geologic Units and Contacts of Natural Bridges National Monument and Vicinity, Utah (NPS, GRI, NABR, NABRGLG)</title>
<edition>1st</edition>
<geoform>vector digital data</geoform>
<lworkcit>
<citeinfo>
<origin>National Park Service Geologic Resources Inventory (GRI) program.</origin>
<pubdate>20010301</pubdate>
<title>Geologic Map of Natural Bridges National Monument and Vicinity, Utah</title>
</citeinfo>
</lworkcit>
</citeinfo>
</citation>
</metadata>

Can you show me the code for the about xml file.

Thanks for you help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top