Commit 53106358 authored by Pietro Abate's avatar Pietro Abate

[r2005-03-07 00:09:50 by afrisch] Partial hack to let PXP read relative external urls

Original author: afrisch
Date: 2005-03-07 00:09:50+00:00
parent d3686111
......@@ -20,7 +20,6 @@ let no_load_url s =
let load_url = ref no_load_url
type kind = File of string | Uri of string | String of string
let kind s =
......@@ -48,16 +47,7 @@ let local s1 s2 =
~base_syntax:(Neturl.url_syntax_of_url url1)
s2 in
Neturl.string_of_url (Neturl.ensure_absolute_url ~base:url1 url2)
(*
match (kind s1, kind s2) with
| File _, File _ ->
Filename.concat s1 s2
| _, (String _ | Uri _) | (String _, File _) ->
s2
| Uri _, File _ ->
if (s1 = "") || (s1.[String.length s1 - 1] = '/') then (s1 ^ s2)
else (s1 ^ "/" ^ s2)
*)
let process s =
match kind s with
| File s -> Location.protect_op "loading file"; Filename s
......
type url = Filename of string | Url of string
(* It recognizes if it is a valid url. If it is connect and bufferize
* in a string otherwise consider it as filename
*)
val process: string -> url
val local: string -> string -> string
val load_url: (string -> string) ref
......@@ -26,7 +26,7 @@ let load_expat s =
Expat.set_end_element_handler p Load_xml.end_element_handler;
Expat.set_character_data_handler p Load_xml.text_handler;
try
match s with
match Url.process s with
| Url.Url s -> Expat.parse p s
| Url.Filename s -> load_from_file p s
with Expat.Expat_error e ->
......
......@@ -18,14 +18,31 @@ let pxp_config =
}
let load_pxp s =
let channel_of_id rt rid =
match rid.rid_system with
| Some local ->
let s = Url.local rt local in
let ch =
match Url.process s with
| Url.Url s -> new Netchannels.input_string s
| Url.Filename s -> raise Not_competent
in
ch, None, None
| None -> raise Not_competent
let load_pxp rt =
try
let src =
match s with
| Url.Url s -> from_string s
| Url.Filename s -> from_file s in
match Url.process rt with
| Url.Url s ->
let channel_of_id = channel_of_id rt in
let r =
new Pxp_reader.resolve_to_any_obj_channel ~channel_of_id () in
from_string ~alt:[r] s
| Url.Filename s -> from_file s in
let mgr = create_entity_manager pxp_config src in
process_entity pxp_config (`Entry_document[`Extend_dtd_fully]) mgr pxp_handle_event;
process_entity pxp_config
(`Entry_document[`Extend_dtd_fully]) mgr pxp_handle_event;
with exn ->
raise (Location.Generic (Pxp_types.string_of_exn exn))
......
......@@ -91,7 +91,6 @@ let xml_parser = ref (fun s -> failwith "No XML parser available")
let load_xml s =
let s = Url.process s in
try
!xml_parser s;
match !stack with
......
......@@ -4,7 +4,7 @@ val load_html: string -> Value.t
(* To define and register a parser *)
val xml_parser: (Url.url -> unit) ref
val xml_parser: (string -> unit) ref
val start_element_handler : string -> (string * string) list -> unit
val end_element_handler : 'a -> unit
......
......@@ -41,11 +41,28 @@ let new_xsd_config () =
let node_of src =
(Pxp_tree_parser.parse_wfdocument_entity (new_xsd_config ()) src spec) # root
open Pxp_types
let channel_of_id rt rid =
match rid.rid_system with
| Some local ->
let s = Url.local rt local in
let ch =
match Url.process s with
| Url.Url s -> new Netchannels.input_string s
| Url.Filename s -> raise Not_competent
in
ch, None, None
| None -> raise Not_competent
let node_of_uri uri =
try
let source = match Url.process uri with
| Url.Filename s -> Pxp_types.from_file s
| Url.Url s -> Pxp_types.from_string s
| Url.Url s ->
let channel_of_id = channel_of_id uri in
let r =
new Pxp_reader.resolve_to_any_obj_channel ~channel_of_id () in
from_string ~alt:[r] s
in
node_of source
with exn -> raise (Location.Generic (Pxp_types.string_of_exn exn))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment