As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
In alfresco community 5.2 I need to read the contents of an XML file when the file is uploaded to a site
What is stopping you from doing that? Without more information about exactly what you are trying to do and where you are stuck we aren't going to be much help, I'm afraid. Sorry.
Gracias por su respuesta
Lo que requiero es cargar un archivo xml en Alfresco, y a través de una
regla ejecutar un script que "lea" algunos datos del archivo que cargó y
los asigne a unas propiedades personalizadas y después distribuya en
carpetas según algunos valores del archivo.
Estoy trabajando en Alfresco community 5.2
Al ejecutar el script para leer el archivo genera un error :...
The processing instruction target matching "[xX][mM][lL]" is not allowed
....
Sandra I. Vásquez R.
*
Donde esta tu script? Puedes lo mostrar aqui? No puedo ayudarte sin el codigo.
Hola
El código del script es :
// buscamos la carpeta logsXML - la creamos si no existevar carpetaBackup = space.childByNamePath("logsXML");if (carpetaBackup == null && space.hasPermission("CreateChildren")){ // crear la carpeta por primera vez carpetaBackup = space.createFolder("logsXML");}
// record the time of the backup to a log file var logFile = carpetaBackup .childByNamePath("archilogXML.txt"); if (logFile == null) { logFile = carpetaBackup .createFile("archilogXML.txt"); }
if (logFile != null) {
if (document.mimetype == "text/xml") {
var docuname = document.name; var mimetype = document.properties.content.mimetype; var docString = document.content; if (docString.startsWith("<?xml")) { docString = docString.split("\n").slice(1).join("\n") } var docXml = new XML(docString); nuevoNombre = docXml.phoneEntry.name; logFile.content += "Tipo Archivo: " + mimetype + "\tFecha: " + new Date().toGMTString() + "\tDoc Name: " + docuname + "\tNuevo Nombre: " + nuevoNombre + "\tContenido Archivo- docXml: " + docXml + ""; }
}
Cuando reviso el archivo creado para el seguimiento del proceso, en Nuevo nombre que es donde quedaría el dato que se debe extraer del xml no aparece nada, como si no interpretara el archivo XML.
Gracias
Gracias por estar pendiente de responder
Anexo un documento xml para revisión
Y en este momento no me genera error la carga del xml, imprimo en el log la variable que contiene los datos del xml cargados pero al extraer los datos no deja nada en la variable
Y se requiere extraer los datos de la etiqueta:
<cac:AccountingContact><cbc:Name>29707543</cbc:Name></cac:AccountingContact>
He probado con
nuevoNombre = docXml.AccountingContact.Name
También con
nuevoNombre = docXml.Name
nuevoNombre = docXml.cbc:Name
Archivo que cargo como ejemplo:
<?xml version="1.0" encoding="UTF-8"?><fe:Invoice xmlns:fe="http://www.dian.gov.co/contratos/facturaelectronica/v1" xmlns="http://www.dian.gov.co/contratos/facturaelectronica/v1" xmlns:cac="urnasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urnasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:clm54217="urn:un:unece:uncefact:codelist:specification:54217:2001" xmlns:clm5639="urn:un:unece:uncefact:codelist:specification:5639:1988" xmlns:clm66411="urn:un:unece:uncefact:codelist:specification:66411:2001" xmlns:clmIANAMIMEMediaType="urn:un:unece:uncefact:codelist:specification:IANAMIMEMediaType:2003" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:ext="urnasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:qdt="urnasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" xmlns:sts="http://www.dian.gov.co/contratos/facturaelectronica/v1/Structures" xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.dian.gov.co/contratos/facturaelectronica/v1 http://www.dian.gov.co/contratos/facturaelectronica/v1%20../xsd/DIAN_UBL.xsd%20urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2%20../../ubl2/common/UnqualifiedDataTypeSchemaModule-2.0.xsd%20urnasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2%20../../ubl2/common/UBL-QualifiedDatatypes-2.0.xsd" xmlns:grl="urn:General:names:specification:ubl:colombia:schema:xsd:GeneralAggregateComponents-1"><ext:UBLExtensions><ext:UBLExtension><ext:ExtensionContent><stsianExtensions><sts:InvoiceControl><sts:InvoiceAuthorization>18762010010595</sts:InvoiceAuthorization><sts:AuthorizationPeriod><cbctartDate>2018-09-01</cbctartDate><cbc:EndDate>2020-09-01</cbc:EndDate></sts:AuthorizationPeriod><sts:AuthorizedInvoices><stsrefix>P1</stsrefix><sts:From>000000001</sts:From><sts:To>000100000</sts:To></sts:AuthorizedInvoices></sts:InvoiceControl><sts:InvoiceSource><cbc:IdentificationCode listAgencyID="6" listAgencyName="United Nations Economic Commission for Europe" listSchemeURI="urnasis:names:specification:ubl:codelist:gc:CountryIdentificationCode-2.0">CO</cbc:IdentificationCode></sts:InvoiceSource></stsianExtensions></ext:ExtensionContent></ext:UBLExtension><ext:UBLExtension><ext:ExtensionContent></ext:ExtensionContent></ext:UBLExtension></ext:UBLExtensions><cbc:UBLVersionID>UBL 2.0</cbc:UBLVersionID><cbcrofileID>DIAN 1.0</cbcrofileID><cbc:ID>P12542</cbc:ID><cbc:IssueDate>2018-10-29</cbc:IssueDate><cbc:IssueTime>10:44:00</cbc:IssueTime><cbc:InvoiceTypeCode listAgencyID="195" listAgencyName="CO, DIAN (Direccion de Impuestos y Aduanas Nacionales)" listSchemeURI="http://www.dian.gov.co/contratos/facturaelectronica/v1/InvoiceType">1</cbc:InvoiceTypeCode><cbc:Note/><cbcocumentCurrencyCode>COP</cbcocumentCurrencyCode><cacrderReference><cbc:ID /></cacrderReference><cac:AdditionalDocumentReference><cbc:ID>152872</cbc:ID><cbcocumentTypeCode>AAJ</cbcocumentTypeCode><cbcocumentType>Remision</cbcocumentType></cac:AdditionalDocumentReference><fe:AccountingSupplierParty><cbc:AdditionalAccountID>1</cbc:AdditionalAccountID><fearty><cacartyIdentification><cbc:ID schemeAgencyID="195" schemeAgencyName="CO, DIAN (Direccion de Impuestos y Aduanas Nacionales)" schemeID="31">805028041</cbc:ID></cacartyIdentification><cacartyName><cbc:Name>SUPERTIENDAS PRUEBA S A</cbc:Name></cacartyName><fehysicalLocation><cbcescription>CALLE 0 3443 214</cbcescription><fe:Address><cbcepartment>VALLE</cbcepartment><cbc:CitySubdivisionName/><cbc:CityName>PALMIRA</cbc:CityName><cac:AddressLine><cbc:Line>CALLE 0 3443 214</cbc:Line></cac:AddressLine><cac:Country><cbc:IdentificationCode>CO</cbc:IdentificationCode></cac:Country></fe:Address></fehysicalLocation><feartyTaxScheme><cbc:TaxLevelCode listName="TIPOS OBLIGACIONES-RESPONSABILIDADES:2016" listSchemeURI="http://www.dian.gov.co" name="Obligado a Facturar Electrónicamente Modelo 2242">O-37</cbc:TaxLevelCode><cac:TaxScheme /></feartyTaxScheme><feartyLegalEntity><cbc:RegistrationName>SUPERTIENDAS PRUEBA S A</cbc:RegistrationName></feartyLegalEntity><cac:Contact><cbc:Name>SUPERTIENDAS PRUEBA S A</cbc:Name><cbc:Telephone>48232175</cbc:Telephone><cbc:Telefax>33234321</cbc:Telefax><cbc:ElectronicMail></cbc:ElectronicMail></cac:Contact></fearty><cac:AccountingContact><cbc:Name>29707543</cbc:Name></cac:AccountingContact><cacellerContact><cbc:Name>ESCOBAR LLORDA MARIA PEREZ</cbc:Name></cacellerContact></fe:AccountingSupplierParty><fe:AccountingCustomerParty><cbc:AdditionalAccountID>2</cbc:AdditionalAccountID><fearty><cacartyIdentification><cbc:ID schemeAgencyID="195" schemeAgencyName="CO, DIAN (Direccion de Impuestos y Aduanas Nacionales)" schemeID="31">3493930</cbc:ID></cacartyIdentification><fehysicalLocation><cbcescription>CR 90a 18 33</cbcescription><fe:Address><cbcepartment>VALLE</cbcepartment><cbc:CitySubdivisionName/><cbc:CityName>CALI</cbc:CityName><cac:AddressLine><cbc:Line>CR 90a 18 33</cbc:Line></cac:AddressLine><cac:Country><cbc:IdentificationCode>CO</cbc:IdentificationCode></cac:Country></fe:Address></fehysicalLocation><feartyTaxScheme><cbc:TaxLevelCode listName="TIPOS OBLIGACIONES-RESPONSABILIDADES:2016" listSchemeURI="http://www.dian.gov.co" name="Ventas régimen común">O-11</cbc:TaxLevelCode><cac:TaxScheme /></feartyTaxScheme><feartyLegalEntity><cbc:RegistrationName>GUILLERMO</cbc:RegistrationName></feartyLegalEntity><feerson><cbc:FirstName>GUILLERMO LEON</cbc:FirstName><cbc:FamilyName>SUAREZ JIMENEZ</cbc:FamilyName><cbc:MiddleName/></feerson></fearty></fe:AccountingCustomerParty><feelivery><feeliveryLocation><cbcescription>GUILLERMO</cbcescription><fe:Address><cbc:ID>CALI</cbc:ID></fe:Address></feeliveryLocation></feelivery><fe:TaxTotal><cbc:TaxAmount currencyID="COP">38217.00</cbc:TaxAmount><cbc:TaxEvidenceIndicator>false</cbc:TaxEvidenceIndicator><fe:TaxSubtotal><cbc:TaxableAmount currencyID="COP">201142.00</cbc:TaxableAmount><cbc:TaxAmount currencyID="COP">38217.00</cbc:TaxAmount><cbcercent>19.00</cbcercent><cac:TaxCategory><cac:TaxScheme><cbc:ID>01</cbc:ID><cbc:TaxTypeCode>01</cbc:TaxTypeCode></cac:TaxScheme></cac:TaxCategory></fe:TaxSubtotal></fe:TaxTotal><fe:LegalMonetaryTotal><cbc:LineExtensionAmount currencyID="COP">201142.00</cbc:LineExtensionAmount><cbc:TaxExclusiveAmount currencyID="COP">201142.00</cbc:TaxExclusiveAmount><cbc:AllowanceTotalAmount currencyID="COP">0.00</cbc:AllowanceTotalAmount><cbcayableAmount currencyID="COP">239359.00</cbcayableAmount></fe:LegalMonetaryTotal><fe:InvoiceLine><cbc:ID>01</cbc:ID><cbc:InvoicedQuantity unitCode="NIU">2</cbc:InvoicedQuantity><cbc:LineExtensionAmount currencyID="COP">101176.00</cbc:LineExtensionAmount><cac:AllowanceCharge><cbc:ChargeIndicator>false</cbc:ChargeIndicator><cbc:AllowanceChargeReasonCode>01</cbc:AllowanceChargeReasonCode><cbc:AllowanceChargeReason>Descuento Linea</cbc:AllowanceChargeReason><cbc:Amount currencyID="COP">0.00</cbc:Amount></cac:AllowanceCharge><cac:TaxTotal><cbc:TaxAmount currencyID="COP">19223.00</cbc:TaxAmount><cbc:TaxEvidenceIndicator>false</cbc:TaxEvidenceIndicator><cac:TaxSubtotal><cbc:TaxableAmount currencyID="COP">120399.00</cbc:TaxableAmount><cbc:TaxAmount currencyID="COP">19223.00</cbc:TaxAmount><cbcercent>19.00</cbcercent><cac:TaxCategory><cac:TaxScheme><cbc:ID>01</cbc:ID><cbc:TaxTypeCode>01</cbc:TaxTypeCode></cac:TaxScheme></cac:TaxCategory></cac:TaxSubtotal></cac:TaxTotal><fe:Item><cbcescription>ARENA FREEMIAU*4500g GATOS</cbcescription><cactandardItemIdentification><cbc:ID>086055</cbc:ID></cactandardItemIdentification></fe:Item><ferice><cbcriceAmount currencyID="COP">60200.00</cbcriceAmount></ferice></fe:InvoiceLine><fe:InvoiceLine><cbc:ID>02</cbc:ID><cbc:InvoicedQuantity unitCode="NIU">4</cbc:InvoicedQuantity><cbc:LineExtensionAmount currencyID="COP">99966.00</cbc:LineExtensionAmount><cac:AllowanceCharge><cbc:ChargeIndicator>false</cbc:ChargeIndicator><cbc:AllowanceChargeReasonCode>01</cbc:AllowanceChargeReasonCode><cbc:AllowanceChargeReason>Descuento Linea</cbc:AllowanceChargeReason><cbc:Amount currencyID="COP">0.00</cbc:Amount></cac:AllowanceCharge><cac:TaxTotal><cbc:TaxAmount currencyID="COP">18994.00</cbc:TaxAmount><cbc:TaxEvidenceIndicator>false</cbc:TaxEvidenceIndicator><cac:TaxSubtotal><cbc:TaxableAmount currencyID="COP">118960.00</cbc:TaxableAmount><cbc:TaxAmount currencyID="COP">18994.00</cbc:TaxAmount><cbcercent>19.00</cbcercent><cac:TaxCategory><cac:TaxScheme><cbc:ID>01</cbc:ID><cbc:TaxTypeCode>01</cbc:TaxTypeCode></cac:TaxScheme></cac:TaxCategory></cac:TaxSubtotal></cac:TaxTotal><fe:Item><cbcescription>ARENA FREEMIAU*10000g GATOS (10k)</cbcescription><cactandardItemIdentification><cbc:ID>086056</cbc:ID></cactandardItemIdentification></fe:Item><ferice><cbcriceAmount currencyID="COP">29740.00</cbcriceAmount></ferice></fe:InvoiceLine></fe:Invoice>
Tienes usar la jerarquía. Trata AccountingSupplierParty.AccountingContact.Name.
Buena noche
Ya probé siguiendo la jerarquía que me indica pero queda nulo el valor, es decir, como si no "interpretara" un archivo tipo xml
Si quito del script la instrucción docString = docString.split("\n").slice(1).join("\n"), sale un error como
Quedo pendiente de su valiosa ayuda.
Aqui es la repuesta...
var docuname = document.name; var mimetype = document.properties.content.mimetype; var docString = document.content; if (docString.startsWith("<?xml")) { docString = docString.split("\n").slice(1).join("\n"); } var docXml = new XML(docString); var cbcNS = new Namespace("urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"); var feNS = new Namespace("http://www.dian.gov.co/contratos/facturaelectronica/v1"); var cacNS = new Namespace("urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"); print("UBLVersionID:" + docXml.cbcNS::UBLVersionID); nuevoNombre = docXml.feNS::AccountingSupplierParty.cacNS::AccountingContact.cbcNS::Name; print("nuevoNombre:" + nuevoNombre);
Con tu XML ejemplo, este nos dar:
UBLVersionID:UBL 2.0nuevoNombre:29707543
UBLVersionID:UBL 2.0
nuevoNombre:29707543
Es importante que eliminar el commentario XML de la primera linea.
Y tienes que declarar y usar namespaces (como se dice "namespaces" en espanol?)
Yo espero este ayudarte.
Y gracias por permitirme practicar mi espanol. Todavia estoy aprendiendo.
Jeff, muchísimas gracias por tu valiosa colaboración
Probé la solución planteada y me funcionó perfectamente, pero ahora tengo el caso de un archivo xml con la misma jerarquía, nomspaces y no funcionó "creería no era reconocido como un archivo tipo xml", después de tanto revisar e contenido y demás del archivo, lo que hice fue copiar todo su contenido en otro archivo en sublime text como tipo xml y de esta forma logré el resultado; el problema es que la carga de esos archivos debe ser automática por lo que no podría estar haciendo un proceso manual de copiar el contenido en otro archivo. Será que hay otra validación que debe tenerse en cuenta para este tipo de casos?... Te agradecería tus recomendaciones para este caso...
El nombre de archivo termina con la extension "xml"? Prodria intenta cambinar el nombre de el archivo.
Quizas un regla podria probar el nombre y lo cambia si no termina con "xml".
No estoy seguro.
Hola buen día
Jeff muchas gracias por tu colaboración. El archivo si tiene la extensión xml en el nombre, solo pasa con un archivo en especial, hice otra prueba donde pasaba los datos del archivo que cargaba a un txt y luego a un xml todo programada con javascript y a través de una regla ejecutando el script pero tampoco funciona. Yo creo que el archivo ha de tener algo especial, porque si selecciono el texto en el editor sublime text y copio en un archivo nuevo lo defino como archivo tipo xml y lo grabo este archivo si lo carga, sin modificar nada del contenido. Qué otra alternativa tengo? o de qué otra manera podría resolverlo por un script y otra opción?