MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: XMLElement with sub-elements?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68354] Re: XMLElement with sub-elements?
  • From: "Norbert Marxer" <marxer at mec.li>
  • Date: Wed, 2 Aug 2006 05:24:13 -0400 (EDT)
  • References: <eandl7$a2g$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi

To get the values for the "name" AND "industry" tag you can use:

factories=Cases[improvements,
  XMLElement["improvement",{},{
     XMLElement["name",{},{name_}],
     XMLElement["industry",{},{value_}]
  }]->{name,value},Infinity]

You can easily get to the expression inside Cases[improvements,expr->
{name, value}, Infinity] by

(1) evaluating your variable improvements
(2) selecting the expression XElement[improvement, ...]; the "
characters for the strings are inserted automatically
(3) replacing the actual names (e.g. "Basic Factory") by name_
(4) replacing the actual industry (e.g. "10") by industry_

Note that there is an error in the example you give (it should read
"industry" instead of "Industry").

Best Regards
Norbert Marxer
www.mec.li


AngleWyrm wrote:
> Hi,
> I want to extract a couple pieces of info from an XML record. I can get just
> one XMLElement child element easily enough, but how to get several?
>
> For example, an xml record set
> <recordset>
>  <improvement>
>   <name>Basic Factory</name>
>   <industry>10</industry>
>  </improvement>
>  <-- more records -->
> </recordset>
>
> To get all industry values, I can gather all cases where the XMLElement
> contains an XMLElement "Industry", like so:
>
> improvements = Import[ filename, "XML"];
> factories = Cases[improvements, XMLElement[_, _,
> {___, XMLElement["Industry", _, {industry_}], ___}
> ] -> {industry}, Infinity]
> 
> How would I get the names AND industry values into a list?


  • Prev by Date: Re: Finding the Number of Pythagorean Triples below a bound
  • Next by Date: Re: RE: Eclipse plugin
  • Previous by thread: Re: XMLElement with sub-elements?
  • Next by thread: Re: Mouse wheel scroll speed