LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-20-2009, 05:06 PM   #1
darthaxul
Member
 
Registered: Aug 2008
Distribution: Devuan; Gentoo; FreeBSD
Posts: 236

Rep: Reputation: 19
get xml elements by name only


I wanted to know if it is possible to get the data for my items based on just the name of the item. for example i need to figure out how many hands the "Giant sword" requires, how do i get it from the xml file? this is only a snippet of the xml...
Code:
<Equipment>
   <Weapon>
     <Melee>
       <Blades>
          <Name>Giant sword</Name>
          <Integrity>10</Integrity>
          <Hands>2</Hands>
          <MinimumEffect>0</MinimumEffect>
          <DamageType>slash</DamageType>
        </Blades>
        <Spears>
          <Name>Pointed spear</Name >
          <Integrity>10</Integrity>
          <Hands>1</Hands>
          <MinimumEffect>0</MinimumEffect>
          <MaximumEffect>5</MaximumEffect>
          <DamageType>pierce</DamageType>
        </Spears>
     </Melee>
     <Magic>
        <Orbs>
          <Name>round orb</Name >
          <Integrity>10</Integrity>
          <Hands>1</Hands>
          <MinimumEffect>0</MinimumEffect>
       </Orbs>
       <Wands>
          <Name>yellow wand</Name >
          <Integrity>10</Integrity>
          <Hands>1</Hands>
          <MinimumEffect>0</MinimumEffect>
        </Wands>
     </Magic>
  </Weapon>
<Equipment>
 
Old 01-20-2009, 06:57 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
The general solution requires a proper XML parser, otherwise its a nightmare to do by hand. Perl has several XML modules eg XML::Simple http://search.cpan.org/~grantm/XML-S.../XML/Simple.pm .
See also the tutorials http://www.perlmonks.org/?node=Tutor...L-Technologies
 
Old 01-24-2009, 10:10 AM   #3
renjithrajasekaran
Member
 
Registered: Jan 2009
Posts: 29

Rep: Reputation: 15
If you're using Java as a programming language - check out this API called CASTOR. It makes reading/writing from/to XML a breeze.

Last edited by renjithrajasekaran; 01-25-2009 at 03:10 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Thinking XML: Firefox 3.0 and XML LXer Syndicated Linux News 0 07-30-2008 06:50 PM
no xml, convert tvtime stationlist to xml for mythtv/freevo... frenchn00b Linux - General 8 11-03-2007 11:35 PM
LXer: StAX’ing up XML: Streaming API for XML LXer Syndicated Linux News 0 11-30-2006 07:54 AM
configure: error: could not find DocBook XML DTD V4.1.2 in XML catalog Fadoksi Linux - Software 1 07-16-2006 06:41 AM
xml elements in css trscookie Programming 3 01-16-2006 10:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration