C
crb
Greetings.
I am in need of perl code that will essentially mimic XML parsing,
since our co. has several dozen systems on which I need to run a
script and none of them have the XML:arser or XML::Simple or XML
modules installed (and doing so is much more trouble than writing a
script to get around the issues).
I'm an infrequent visitor to the world of perl, and have struggled w/
this one the past few days. Since it's probably something that someone
has done, I figured I'd post the request here.
I'm trying to parse out specific items in XML tags where the tags
could appear in multiple places in the XML file.
What I need is looping logic that, when it encounters a tag named,
say, <components type="...">, it will loop thru until it finds a tag
called <item> and then grabs some of the parameters of <item>. It has
to know that when it reaches </components>, it's done w/ that
component and captures that specific <item>. So the XML looks like:
<components type="type1">
<services .../>
<item color="red" size="large"/>
</components>
<components type="type2">
<services .../>
<item color="red" size="small"/>
</components>
The problem/issue I'm facing now is that there are several
<components> and <item> tags in the XML.
I know how to find the component I'm looking for (i.e.
while (<FILDHANDLE>) {
next if ( /^\s+\<components type=(.*) .*$/ );
if ( $1 = 'type1' ) {
. . .
}
. . .
}
but I need to capture the <item> for <components type="type1"> before
I encounter an <item> for <components type="type2">. Searching for
<item color=(.*)...> is not enough, since this information can be
duplicated across several <components> in the XML file.
Hopefully that adequately explains what I'm trying to do. Any help
would be greatly appreciated.
thx,
~~crb
I am in need of perl code that will essentially mimic XML parsing,
since our co. has several dozen systems on which I need to run a
script and none of them have the XML:arser or XML::Simple or XML
modules installed (and doing so is much more trouble than writing a
script to get around the issues).
I'm an infrequent visitor to the world of perl, and have struggled w/
this one the past few days. Since it's probably something that someone
has done, I figured I'd post the request here.
I'm trying to parse out specific items in XML tags where the tags
could appear in multiple places in the XML file.
What I need is looping logic that, when it encounters a tag named,
say, <components type="...">, it will loop thru until it finds a tag
called <item> and then grabs some of the parameters of <item>. It has
to know that when it reaches </components>, it's done w/ that
component and captures that specific <item>. So the XML looks like:
<components type="type1">
<services .../>
<item color="red" size="large"/>
</components>
<components type="type2">
<services .../>
<item color="red" size="small"/>
</components>
The problem/issue I'm facing now is that there are several
<components> and <item> tags in the XML.
I know how to find the component I'm looking for (i.e.
while (<FILDHANDLE>) {
next if ( /^\s+\<components type=(.*) .*$/ );
if ( $1 = 'type1' ) {
. . .
}
. . .
}
but I need to capture the <item> for <components type="type1"> before
I encounter an <item> for <components type="type2">. Searching for
<item color=(.*)...> is not enough, since this information can be
duplicated across several <components> in the XML file.
Hopefully that adequately explains what I'm trying to do. Any help
would be greatly appreciated.
thx,
~~crb