Toby Inkster avatar Toby Inkster committed df8f9de

xml:base now works.

Comments (0)

Files changed (2)

 use RDF::Trine::Serializer::NTriples;
 use LWP::Simple;
 use XML::Atom::OWL;
+use File::Slurp qw(slurp);
 
 my $u = "http://bblfish.net/work/atom-owl/2006-06-06/examples/example-2.atom";
-my $p = XML::Atom::OWL->new(get($u), $u);
+my $d = get($u);
+my $p = XML::Atom::OWL->new($d, $u);
 $p->consume;
 
 my $s = RDF::Trine::Serializer::NTriples->new;

lib/XML/Atom/OWL.pm

 use LWP::UserAgent;
 use RDF::Trine 0.112;
 use URI;
+use URI::URL;
 use XML::LibXML qw(:all);
 
 use constant ATOM_NS =>  'http://www.w3.org/2005/Atom';
 	}
 	
 	my $base = $this->{baseuri};
-	if ($this->{'options'}->{'xml_base'})
+	if ($opts->{'element'})
 	{
-		$base = $opts->{'xml_base'} || $this->{baseuri};
+		$base = $this->get_node_base($opts->{'element'});
 	}
 	
 	my $url = url $param, $base;
 	my $this = shift;
 	my $node = shift;
 
-	my $XML_XHTML_NS = 'http://www.w3.org/1999/xhtml';
-
 	if ($node->hasAttributeNS(XML_XML_NS, 'lang'))
 	{
 		return valid_lang($node->getAttributeNS(XML_XML_NS, 'lang')) ?
 	return undef;
 }
 
+sub get_node_base
+{
+	my $this = shift;
+	my $node = shift;
+
+	my @base;
+
+	while (1)
+	{
+		push @base, $node->getAttributeNS(XML_XML_NS, 'base')
+			if $node->hasAttributeNS(XML_XML_NS, 'base');
+			
+		$node = $node->parentNode;
+		last unless UNIVERSAL::isa($node, 'XML::LibXML::Element');
+	}
+	
+	my $rv = url $this->uri; # document URI.
+	
+	while (my $b = pop @base)
+	{
+		$rv = url $b, $rv->abs->as_string;
+	}
+	
+	return $rv->abs->as_string;
+}
+
+
 =item $p->graph() 
 
 This method will return an RDF::Trine::Model object with all
 	my $this    = shift;
 	my $element = shift;
 	
+	if (defined $this->{'bnode_generator'})
+	{
+		return $this->{'bnode_generator'}->bnode($element);
+	}
+	
 	return sprintf('_:AwolAutoNode%03d', $this->{bnodes}++);
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.