Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: difficulties with xml

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69371] Re: difficulties with xml
  • From: "Norbert Marxer" <marxer at mec.li>
  • Date: Sat, 9 Sep 2006 03:26:51 -0400 (EDT)
  • References: <edjh41$lu3$1@smc.vnet.net>

Hi Pascal

If I have the following list (your data):

li = {
  XMLElement[ensemble, {ensemble -> 1},
     {XMLElement[peak, {peakID -> 1},
        {XMLElement[freq, {}, {3.123}], XMLElement[vol, {}, {12.12}]}],
      XMLElement[peak, {peakID -> 2},
        {XMLElement[freq, {}, {8.101}], XMLElement[vol, {},
{0.552}]}]}],
  XMLElement[ensemble, {ensemble -> 2},
    {XMLElement[peak, {peakID -> 1},
        {XMLElement[freq, {}, {6.163}], XMLElement[vol, {}, {2.111}]}],
     XMLElement[peak, {peakID -> 2},
        {XMLElement[freq, {}, {12.884}],  XMLElement[vol, {},
{0.221}]}]}]
};

then you can use the following replacement

li /.
XMLElement[ensemble, {ensemble -> 2},
     {aaaa1_,
      XMLElement[peak, {peakID -> 2},
         { XMLElement[freq, {}, _], aaaa2_}]}] ->
XMLElement[ensemble, {ensemble -> 2},
     {aaaa1,
      XMLElement[peak, {peakID -> 2},
        { XMLElement[freq, {}, {"MY VALUE"}], aaaa2}]}]

to set the freq value (to "MY VALUE") of ensemble 2 and peakID 2.

Best Regards
Norbert Marxer
www.mec.li


Pascal Mercier wrote:
> Dear all,
>
> I am having problems accessing and changing xml attributes/properties
> after importing an xml file and I'm looking for some help.
>
> z=Import["xmltest.xml","XML"];
>
> part of z looks like the following (sorry for the long lines here)
>
> XMLElement[ensemble, {ensemble->1}, { XMLElement[peak, {peakID->1},
> { XMLElement [freq,{},{3.123}] ,  XMLElement [vol,{},{12.12}] } ] ,
> XMLElement[peak, {peakID->2},  { XMLElement [freq,{},{8.101}] ,
> XMLElement [vol,{},{0.552}] }]}]
> XMLElement[ensemble, {ensemble->2}, { XMLElement[peak, {peakID->1},
> { XMLElement [freq,{},{6.163}] ,  XMLElement [vol,{},{2.111}] } ] ,
> XMLElement[peak, {peakID->2},  { XMLElement [freq,{},{12.884}] ,
> XMLElement [vol,{},{0.221}] }]}]
> .
> .
> .
>
> Could anybody give me an hint about the correct syntax to use to be
> be able to directly access and change the value of the freq attribute
> of peakID2 of ensemble2 for instance?
> I just can't seem to be able to find it after reading Mathematica's
> documentation.
> 
> Thanks so much in advance,
> 
> Pascal


  • Prev by Date: Re: solve the following problem
  • Next by Date: Re: Re: Why doesn't Mathematica solve this simple differential equation?
  • Previous by thread: Re: Re: difficulties with xml
  • Next by thread: Batch evaluation of multiple notebooks?