@@ -15,6 +15,7 @@ import { dirname, isAbsolute, resolve } from "node:path";
1515import { Readable } from "node:stream" ;
1616import { fileURLToPath } from "node:url" ;
1717import { Catalog } from "./Catalog" ;
18+ import { Constants } from "./Constants" ;
1819import { ContentHandler } from "./ContentHandler" ;
1920import { FileReader } from "./FileReader" ;
2021import { NeedMoreDataError } from "./NeedMoreDataError" ;
@@ -942,31 +943,22 @@ export class SAXParser {
942943 this . pointer = 0 ;
943944 this . contentHandler ?. processingInstruction ( target , data ) ;
944945
945- // TODO enable RelaxNG parsing from xml-model processing instruction
946-
947- /*
948946 if ( target === 'xml-model' ) {
949- // Extract default attributes from RelaxNG schemas
950- let atts: Map<string, string> = this.parseAttributes(data);
951- let href: string = '';
952- let schemaType: string = '';
953- for (let [key, value] of atts.entries()) {
954- if (key === 'href') {
955- href = value;
956- }
957- if (key === 'schematypens') {
958- schemaType = value;
959- }
960- }
961- if (href !== '' && Constants.RELAXNG_NS_URI === schemaType) {
947+ const attributesFromPi : Map < string , string > = this . parseAttributes ( data ) ;
948+ const href : string | undefined = attributesFromPi . get ( 'href' ) ;
949+ const schemaType : string | undefined = attributesFromPi . get ( 'schematypens' ) ;
950+ if ( href && schemaType === Constants . RELAXNG_NS_URI ) {
962951 try {
963952 this . parseRelaxNG ( href ) ;
964- } catch (e: Error | any) {
965- // do nothing
953+ } catch ( error ) {
954+ if ( this . validating ) {
955+ throw error ;
956+ }
957+ const message : string = error instanceof Error ? error . message : String ( error ) ;
958+ console . warn ( `Warning: Could not load RelaxNG defaults from ${ href } : ${ message } ` ) ;
966959 }
967960 }
968961 }
969- */
970962 }
971963
972964 parseRelaxNG ( href : string ) {
@@ -1762,6 +1754,16 @@ export class SAXParser {
17621754 const parsed : number = Number . parseInt ( entityName . substring ( 1 ) , 10 ) ;
17631755 XMLUtils . ensureValidXmlCodePoint ( this . xmlVersion , parsed , `character reference &#${ entityName . substring ( 1 ) } ; in attribute value` ) ;
17641756 result += String . fromCodePoint ( parsed ) ;
1757+ } else if ( entityName === 'lt' ) {
1758+ result += '<' ;
1759+ } else if ( entityName === 'gt' ) {
1760+ result += '>' ;
1761+ } else if ( entityName === 'amp' ) {
1762+ result += '&' ;
1763+ } else if ( entityName === 'apos' ) {
1764+ result += '\'' ;
1765+ } else if ( entityName === 'quot' ) {
1766+ result += '"' ;
17651767 } else {
17661768 const replacement : string | undefined = grammar ?. resolveEntity ( entityName ) ;
17671769 if ( replacement !== undefined ) {
0 commit comments