S
Sara
Hi all,
I have just started using XML::* modules for validating XML files and
I am trying to understand which module ('tree' or 'stream') would fit
for my requirement which is to get data (a specific nodelist) from a
simple external XML file based on user-input and use it to validate a
source XML file, more specifically the content of elements in the XML
file.
For instance the content of element 'figure' should start with a
string matching regex /^Fig\. \d+\b/. The external file would be
having the format of the element's content in regex format. I have
planned to use XML::XPath for reading the external XML file, but still
undecided about what to use for validating the source XML file because
of the following points.
Is there a better way of doing the following piece of code, in terms
of ease of maintenance and secondarily, code size.
sub start_element {
my ($self, $element) = @_;
if ($element->{Name} eq 'body') {
....
}
elsif ($element->{Name} eq 'head') {
....
}
}
Because if the element 'head' is removed or renamed then the code
would have to be changed. Instead if it was independent of the element
name this change would be eliminated.
Is XML::Checker the only module in CPAN to
1. check if ID of an element was defined
2. get number of times the ID was referenced?
I would prefer not to write less-optimized blocks of code if someone
has already done that in a far more better manner.
Finally, can someone please help or point me to help using namespaces
in SAX.
Thanks,
Sara
I have just started using XML::* modules for validating XML files and
I am trying to understand which module ('tree' or 'stream') would fit
for my requirement which is to get data (a specific nodelist) from a
simple external XML file based on user-input and use it to validate a
source XML file, more specifically the content of elements in the XML
file.
For instance the content of element 'figure' should start with a
string matching regex /^Fig\. \d+\b/. The external file would be
having the format of the element's content in regex format. I have
planned to use XML::XPath for reading the external XML file, but still
undecided about what to use for validating the source XML file because
of the following points.
Is there a better way of doing the following piece of code, in terms
of ease of maintenance and secondarily, code size.
sub start_element {
my ($self, $element) = @_;
if ($element->{Name} eq 'body') {
....
}
elsif ($element->{Name} eq 'head') {
....
}
}
Because if the element 'head' is removed or renamed then the code
would have to be changed. Instead if it was independent of the element
name this change would be eliminated.
Is XML::Checker the only module in CPAN to
1. check if ID of an element was defined
2. get number of times the ID was referenced?
I would prefer not to write less-optimized blocks of code if someone
has already done that in a far more better manner.
Finally, can someone please help or point me to help using namespaces
in SAX.
Thanks,
Sara