PDA

Click to See Complete Forum and Search --> : XML and Perl



Do5
06-03-2001, 01:18 PM
HI, i am really new to XML.
I know how XML works by using parent and child tags
ie:
{parent}
{child}value{/child}
{/parent}

and i want to get the value of the child and asign it to a string. to do that i must open the load the local file
and take the value by using this method:


($child) = <XMLFILE>=~ /\<child\>(.*)\<\/child\>/;

ok thats how i can get the value of the child.
my question is how can i get the value of the child and name of parent:

{parent name="sam"}
{child}value{/child}
{/parent}

*note please replace {} with <>, this board somehow wont display xml code

[Edited by Do5 on 06-03-2001 at 01:21 PM]

hal(var)
06-05-2001, 01:30 AM
&lt;parent name="sam">
&lt;child>value&lt;/child>
&lt;/parent>



($child) = &lt;XMLFILE>=~ /\&lt;child\>(.*)\&lt;\/child\>/;


well you could
use XML::Parser;

or, but only for this very specific document


while (&lt;XMLFILE>=~ ) {
if ($_ =~ /\&lt;child\>(.*)\&lt;\/child\>/) {
$child = $1;
}
if ($_ =~ /\&lt;parent\s.*name="(.*?)"/) {
$parentName= $1;
}
}

this is untested code.

Do5
06-05-2001, 08:29 AM
Thanks
i must of mistype my question;
ok thats how i can get the value of the child.
my question is how can i get the value of the child and name of parent:

{parent name="sam"}
{child}value{/child}
{/parent}
but heres half of the question i how would how can i get the value of the child by the name of parent
{parent name="sam"}
{child}michael{/child}
{/parent}
{parent name="jon"}
{child}lisa{/child}
{/parent}



[Edited by Do5 on 06-05-2001 at 03:47 PM]