Dear Micheal,
I have some small experience with perl and XML (my first realy perl
programming).
For parsing I prefer XML::Twig.
You can easy bind a subtree as root element to a pointer.
With the function xpath you can retrieve the content of the tag you want.
Example:
$hash->{"BuyerLineItemNum"}=give_v($IDtwig,"BaseItemDetail/LineItemNum/BuyerLineItemNum","NOCOMMIT");
The subroutine:
sub give_v
{
my ($twig,$path, $comment)=@_;
my $field;
my @value=$twig->root->get_xpath("$path");
if ( defined($value[0]) )
{
$field=$value[0]->field;
if (!(defined($field)))
{
$errorstr.= "$comment Error in path $path, value is not defined, set
to \"\" \n";
$field="";
}
}
else
{
$errorstr.= "$comment Error in path $path, Path not defined, set field
\"\" \n";
$field="";
}
return $field;
}
If you have items (things which occurs several times with the same tag name)
you can do that like this:
foreach $ItemDetail ($new_twig[0]->children)
{
my $IDtwig= new XML::Twig( );
$IDtwig->parse($ItemDetail->sprint);
my $hash;
$hash->{"PricingDetail_UOMCodedOther"}=give_v($IDtwig,"PricingDetail/ListOfPrice/Price/PriceBasisQuantity/Quantity/UnitOfMeasurement/UOMCodedOther","NOCOMMIT");
$index+=1;
push @AItemDetail, $hash ;
}
All in all, the XML::Twig-Modul looks realy "perlish", I'm shure that I don't
have use every advantage of this modul.
I find XML:Simple very difficult to use, because you have to define a variable
with a structure like the XML-File you will parse.
OK, if you will create a XML-File, this is a easy task.
Here is an example:
#!/usr/bin/perl
use strict;
use XML::Simple;
my $person=XMLin('./person.xml');
print "$person->{first_name} $person->{last_name}\n";
print "$person->{hobbie}->[0], \n";
my $catalog = XMLin('./catalog.xml');
print $catalog->{part}->[0]->{desc}, "\n";
foreach my $part (@{$catalog->{part}}) {
if($part->{partnum} eq '9344675') {
print $part->{desc}, "\n";
last;
}
}
If you change your XML-Structure, you must change your code!
To create XML-Files I do this in a very special way: I take a predefine
XML-FIle with special pattern inside. This pattern will then be placed by the
information. This is not what is good for you, I think.
I think to use XSL-Transfomer is a good idea, because you only need define for
each tag the format in which it will be transformed. You only need to change
the style file to create or to not create menus.
To use DOM is slow and hart. To create a new tag at a position in a XML-Tree
looks like hand make: you have to go with a curser to the position and then
to add the new subtree. And you have the complete tree in your RAM, the
performce on high load The same you can to with Twig more easy.
DOM do not like spaces. In XML each space is a tag!.
I hope this may help.
Greetings
Harald
On Sunday 16 February 2003 15:50, Michael Bell wrote:
> Hi all,
>
> because of the reorganization of our code we have to think about two new
> areas XML and ACLs.
>
> The todays implementation of ACL is not really easy to understand and
> manage. Therefore we think about a reorganization. Does anybody has a
> opinion about Data::ACL or Decision::ACL?
>
> We want generate our menus dynamical. The description of the menus
> should be included in an XML file. This XML-file should be parsed and
> then a script should generate a XHTML-file. Any ideas are welcomed. We
> think about things like XML::XSLT, XML::DOM and XML::Generator.
> Massimiliano manages this area but we are pleased with any ideas,
> recommendations or help.
>
> Best regards
>
> Michael
--
Dr. Harald Wallus
Results GmbH
Am Listholze 78, D-30177 Hannover
Tel: +49(0)511 90 95 1-23 Fax: +49(0)511 90 95 = 1-90
Email: [EMAIL PROTECTED]
Internet: http://www.results-hannover.de
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Openca-Users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/openca-users