Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Internet
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Colaboración Paypal con ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #11  
Antiguo 26-10-2021
unomasmas unomasmas is offline
Miembro
 
Registrado: dic 2019
Posts: 194
Poder: 7
unomasmas Va por buen camino
Cita:
Empezado por Ramon88 Ver Mensaje
Alguien sabría decirme el targetNamespace ??
Estoy intentando validar XML con el esquema XSD, y urn:ticketbai:emision no sirve, y si al pasarlo pongo nothing, no me funciona:
Código:
Dim schemas As New XmlSchemaSet()
schemas.Add(targetNamespace , pathXSD)
Creo que el problema está en la línea <import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd"/>. Parece que hay algún tipo de bloqueo en w3.org. Después de muchas vueltas, encontré la solución descargando el fichero y añadiéndolo como segundo esquema, sin más, desde local. Te dejo mi clase:

Código:
using System;
using System.Windows.Forms;
using System.Net;

using System.Xml;
using System.Xml.Linq;
using System.Xml.Schema;

namespace tBAI
{
    public class Validaciones_Formato
    {
        private bool _isValid { get; set; }
        private string _noValidInformation { get; set; }
        private string _error;

        public bool ValidaXmlFactura(string xmlFile)
        {
            try
            {
                _isValid = true;
                // Ficheros xsd ubicados en la raíz del ejecutable
                string xsdFile = @"ticketBaiV1-2.xsd";
                string xsdFile2 = @"xmldsig-core-schema.xsd";

                var path = new Uri(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)).LocalPath;
                XmlSchemaSet schema = new XmlSchemaSet();
                schema.Add("urn:ticketbai:emision", path + "\\" + xsdFile);
                schema.Add("http://www.w3.org/2000/09/xmldsig#", path + "\\" + xsdFile2);

                using (XmlReader rd = XmlReader.Create(xmlFile))
                {
                    XDocument doc = XDocument.Load(rd);
                    doc.Validate(schema, ValidationCallBack);
                }

                if (!_isValid)
                {
                    MessageBox.Show(_noValidInformation.TrimEnd(Environment.NewLine.ToCharArray()), System.Reflection.MethodBase.GetCurrentMethod().Name, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                }
                return _isValid;
            }
            catch (Exception ex)
            {
                //isValid = false; no need to say isValid=false as it returns false
                _error = ex.Message;
                MessageBox.Show(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                return false;
            }
        }

        public string GetNoValidInformation()
        {
            return _noValidInformation;
        }

        public string GetErrorMsg()
        {
            return _error;
        }

        private void ValidationCallBack(object sender, ValidationEventArgs e)
        {
            _noValidInformation += string.Format("+ {0}: {1}", e.Severity.ToString(), e.Message) + Environment.NewLine;
            _isValid = false;
        }
    }
}
Responder Con Cita
 


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
SII -Nuevo sistema de la Agencia Tributaria española de envío de datos vía Webservice newtron Internet 3716 19-01-2026 20:01:34
Como utilizar la ayuda del nuevo Sistema Operativo gluglu Humor 3 24-09-2007 09:39:05
Aplicacion Agencia De Viajes ArdiIIa Varios 9 20-01-2007 16:49:53
El Vasco Aguirre Al González La Taberna 5 26-05-2006 09:22:28
Microsoft ha lanzado su nuevo sistema operativo DarkByte Humor 0 25-01-2004 09:21:14


La franja horaria es GMT +2. Ahora son las 22:33:51.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi