OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

entity-resolution message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]


Subject: Publicid <-> URN conversion code in Perl


Here are two Perl programs to convert publicids to URNs
and URNs to publicids.  We should publish these on the
Web page as reference code, once they have been checked.
I have run all the examples in the I-D through them.

-- 
There is / one art             || John Cowan <jcowan@reutershealth.com>
no more / no less              || http://www.reutershealth.com
to do / all things             || http://www.ccil.org/~cowan
with art- / lessness           \\ -- Piet Hein
#!/usr/bin/perl -w
# Convert a "publicid" URN to an SGML/XML public identifier
# No copyright, no warranty, use as you will
# John Cowan asserts the moral right to be known as the author of this code

use strict;

while (<>) {
	chomp;

	# verify
	unless (s/^urn:publicid://) {
		warn "$_ is not a publicid URN\n";
		next;
		}

	# remap
	s/\+/ /g;
	s/:/\/\//g;
	s/;/::/g;
	s/%(..)/sprintf("%c", hex($1))/eg;
	print $_, "\n";
	}
#!/usr/bin/perl -w
# Convert an SGML/XML public identifier to an URN
# No copyright, no warranty, use as you will
# John Cowan asserts the moral right to be known as the author of this code

use strict;

while (<>) {
	# check validity
	if (/[^ \r\na-zA-Z0-9'()+,.\/:=?;!*#\@\$_%-]/) {
		warn "invalid public id: $_";
		next;
		}

	# normalize
	s/[\r\n ]+/ /g;
	s/^ //;
	s/ $//;

	# remap
	s/%/%25/g;
	s/;/%3B/g;
	s/::/;/g;
	s/:/%3A/g;
	s/\/\//:/g;
	s/\//%2F/g;
	s/\+/%2B/g;
	s/ /+/g;
	s/'/%27/g;
	s/\?/%3F/g;
	s/#/%23/g;

	# output
	print "urn:publicid:", $_, "\n";
	}


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]


Powered by eList eXpress LLC