@nodecfdi/xml-resource-retriever
XSD and XLST resource downloader for local storage
@nodecfdi/xml-resource-retriever
The purpose of this library is to download recursively XML resources from the internet to a local storage for further
usage. At this moment it only allows Schemas (XSL) and Transformations (XSLT) but is easily extensible implementing
the RetrieverInterface
interface or extending the AbstractXmlRetriever
class.
For every downloaded file it will override its dependence's to a relative location, in this way, every dependence should be available to work offline.
You can use the local object NodeDownloader
that simply uses copy function to get and store a file from internet. You
can also use your own implementation of the DownloaderInterface according to your needs. If you built a configurable and
useful downloader class feel free to contribute it to this project.
Based on php version repo: https://github.com/eclipxe13/XmlResourceRetriever
NPM
npm i @nodecfdi/xml-resource-retriever --save
YARN
yarn add @nodecfdi/xml-resource-retriever
PNPM
pnpm add @nodecfdi/xml-resource-retriever
Example with xmldom
import { install } from '@nodecfdi/cfdiutils-common';
import { XMLSerializer, DOMParser, DOMImplementation } from '@xmldom/xmldom';
import { XsltRetriever } from '@nodecfdi/xml-resource-retriever';
install(new DOMParser(), new XMLSerializer(), new DOMImplementation());
const xslt = new XsltRetriever('/project/cache');
const local = await xslt.retrieve('http://www.sat.gob.mx/sitio_internet/cfd/3/cadenaoriginal_3_3/cadenaoriginal_3_3.xslt');
console.log(local); /* /project/cache/www.sat.gob.mx/sitio_internet/cfd/3/cadenaoriginal_3_3/cadenaoriginal_3_3.xslt */
Example with jsdom
import { install } from '@nodecfdi/cfdiutils-common';
import { JSDOM } from 'jsdom';
import { XsltRetriever } from 'nodecfdi/xml-resource-retriever';
const dom = new JSDOM();
const jsDOMParser = new dom.window.DOMParser();
const jsXMLSerializer = new dom.window.XMLSerializer();
const jsDOMImplementation = dom.window.document.implementation;
install(jsDOMParser, jsXMLSerializer, jsDOMImplementation);
const xslt = new XsltRetriever('/project/cache');
const local = await xslt.retrieve('http://www.sat.gob.mx/sitio_internet/cfd/3/cadenaoriginal_3_3/cadenaoriginal_3_3.xslt');
console.log(local); /* /project/cache/www.sat.gob.mx/sitio_internet/cfd/3/cadenaoriginal_3_3/cadenaoriginal_3_3.xslt */
These methods apply to XslRetriever
and XsltRetriever
retrieve(url)
Download recursively an url and store it into the retriever base path, it changes the child elements
that contains references to other files.download(url)
Download an url and store it into the retriever base path. It does not validate the file for xml
errors. It does not download dependence's.buildPath(url)
Return the location of were a file should be stored according to the base path.setDownloader(downloader)
Change the default NodeDownloader
to a custom implementation.XsdRetriever
search for namespace http://www.w3.org/2001/XMLSchema
elements import
and include
.
XsltRetriever
search for namespace http://www.w3.org/1999/XSL/Transform
elements import
and include
.
Puedes obtener soporte abriendo un ticket en Github.
Adicionalmente, esta librería pertenece a la comunidad OcelotlStudio, así que puedes usar los mismos canales de comunicación para obtener ayuda de algún miembro de la comunidad.
Esta librería se mantendrá compatible con al menos la versión con soporte activo de Node más reciente.
También utilizamos Versionado Semántico 2.0.0 por lo que puedes usar esta librería sin temor a romper tu aplicación.
Las contribuciones con bienvenidas. Por favor lee CONTRIBUTING para más detalles y recuerda revisar el archivo CHANGELOG.
The @nodecfdi/xml-resource-retriever
library is copyright © NodeCfdi - OcelotlStudio and licensed for use under the MIT License (MIT). Please see LICENSE for more information.