tag 337584 patch
thanks

On Tue, Mar 07, 2006 at 09:32:24PM -0500, Charles Fry wrote:
> > If the DTD is unavailable and the document actually uses the DTD, not
> > retrieving the remote DTD will result in different output than if the
> > remote DTD is present.
> 
> I guess I am not familiar enough with xpath to conceive of a case when
> the DTD would change the xpath result. Any demonstration of this would
> be appreciated. :-)

Hi,

from the XPath specification, section 5.3 ("Attribute Nodes") [1]:

  NOTE: It is possible for default attributes to be declared in an
  external DTD or an external parameter entity. The XML Recommendation
  does not require an XML processor to read an external DTD or an
  external parameter unless it is validating. A stylesheet or other
  facility that assumes that the XPath tree contains default attribute
  values declared in an external DTD or parameter entity may not work
  with some non-validating XML processors.

[1] http://www.w3.org/TR/xpath#attribute-nodes

Generally, the XML 'standalone' declaration [2] should be set to "yes"
if external references don't affect the information. This is honoured
by XML::XPath (or rather the XML::Parser object inside), so it won't
try to load the DTD if standalone="yes".

[2] http://www.w3.org/TR/REC-xml/#sec-rmd

> > What you probably should be doing is providing the DTD that you want
> > to use to create these XML files so there is no external reference.
> > Otherwise your packages could build differently depending on whether
> > or not the DTD is present, which is definetly not what you want. [If
> > the DTD isn't necessary, then it probably shouldn't be specified
> > either.]
> 
> Unfortunately the files processed are from various external sources, and
> are not under our control.

> Perhaps what we need is a flag to prevent the DTD from being used, or to
> prevent attempts to fetch it from the network?

I'm attaching a patch for a new xpath "-n" option that makes XML::Parser
be used with 'ParseParamEnt => 0' so that the DTD won't be loaded.

Cheers,
-- 
Niko Tyni   [EMAIL PROTECTED]
diff --git a/XPath.pm b/XPath.pm
index 579d2cd..899cd1e 100644
--- a/XPath.pm
+++ b/XPath.pm
@@ -8,6 +8,7 @@ use vars qw($VERSION $AUTOLOAD $revision);
 $VERSION = '1.13';
 
 $XML::XPath::Namespaces = 1;
+$XML::XPath::ParseParamEnt = 1;
 $XML::XPath::Debug = 0;
 
 use XML::XPath::XMLParser;
diff --git a/XPath/XMLParser.pm b/XPath/XMLParser.pm
index 78664d3..f13dc19 100644
--- a/XPath/XMLParser.pm
+++ b/XPath/XMLParser.pm
@@ -53,7 +53,7 @@ sub parse {
     
     my $parser = $self->get_parser || XML::Parser->new(
             ErrorContext => 2,
-            ParseParamEnt => 1,
+            ParseParamEnt => $XML::XPath::ParseParamEnt,
             );
     
     $parser->setHandlers(
diff --git a/examples/xpath b/examples/xpath
index d0462eb..5536757 100755
--- a/examples/xpath
+++ b/examples/xpath
@@ -37,6 +37,11 @@ PARSE: while ((@ARGV >= 1) && ($ARGV[0] =~ /^-./ )) {
 			shift;
 			last OPTIONS;
 		}
+		if ($ARGV[0] eq "-n") {
+			$XML::XPath::ParseParamEnt = 0;	
+			shift;
+			last OPTIONS;
+		}
 		print STDERR "Unknown option ignore: ", shift;
 	}
 }
@@ -55,6 +60,7 @@ $0 [options] -e query [-e query...] [filename...]
 	-q		quiet. Only output the resulting PATH
 	-s suffix	use suffix instead of linefeed.
 	-p postfix	use prefix instead of nothing.
+	-n		Don't use an external DTD.
 );
 	exit;
 }
@@ -131,7 +137,7 @@ xpath - a script to query XPath statements in XML documents.
 
 =head1 SYNOPSIS
 
-B<xpath [-s suffix] [-p prefix] [-q] -e query [-e query] ... [file] ...>
+B<xpath [-s suffix] [-p prefix] [-n] [-q] -e query [-e query] ... [file] ...>
 
 =head1 DESCRIPTION
 
@@ -154,6 +160,11 @@ The context of the first query is always the root of the current document.
 
 Be quiet. Output only errors (and no separator) on stderr.
 
+=head2 B<-e>
+
+Never use an external DTD, ie. instantiate the XML::Parser module
+with 'ParseParamEnt => 0'.
+
 =head2 B<-s suffix>
 
 Place C<suffix> at the end of each entry. Default is a linefeed.

Reply via email to