public void TestAdd () { XmlSchemaCollection col = new XmlSchemaCollection (); XmlSchema schema = new XmlSchema (); XmlSchemaElement elem = new XmlSchemaElement (); elem.Name = "foo"; schema.Items.Add (elem); schema.TargetNamespace = "urn:foo"; col.Add (schema); col.Add (schema); // No problem !? XmlSchema schema2 = new XmlSchema (); schema2.Items.Add (elem); schema2.TargetNamespace = "urn:foo"; col.Add (schema2); // No problem !! schema.Compile (null); col.Add (schema); col.Add (schema); // Still no problem !!! schema2.Compile (null); col.Add (schema2); schema = GetSchema ("Test/XmlFiles/xsd/3.xsd"); schema.Compile (null); col.Add (schema); schema2 = GetSchema ("Test/XmlFiles/xsd/3.xsd"); schema2.Compile (null); col.Add (schema2); }
public bool Execute(XmlSchema schema, string targetNamespace, bool loadExternals, XmlSchemaCollection xsc) { this.schema = schema; Xmlns = NameTable.Add("xmlns"); Cleanup(schema); if (loadExternals && xmlResolver != null) { schemaLocations = new Hashtable(); //new Dictionary<Uri, Uri>(); if (schema.BaseUri != null) { schemaLocations.Add(schema.BaseUri, schema.BaseUri); } LoadExternals(schema, xsc); } ValidateIdAttribute(schema); Preprocess(schema, targetNamespace, Compositor.Root); if (!HasErrors) { schema.IsPreprocessed = true; for (int i = 0; i < schema.Includes.Count; ++i) { XmlSchemaExternal include = (XmlSchemaExternal)schema.Includes[i]; if (include.Schema != null) { include.Schema.IsPreprocessed = true; } } } return !HasErrors; }
/// <summary> /// Valida se um Xml está seguindo de acordo um Schema /// </summary> /// <param name="arquivoXml">Arquivo Xml</param> /// <param name="arquivoSchema">Arquivo de Schema</param> /// <returns>True se estiver certo, Erro se estiver errado</returns> public void ValidaSchema(String arquivoXml, String arquivoSchema) { //Seleciona o arquivo de schema de acordo com o schema informado //arquivoSchema = Bll.Util.ContentFolderSchemaValidacao + "\\" + arquivoSchema; //Verifica se o arquivo de XML foi encontrado. if (!File.Exists(arquivoXml)) throw new Exception("Arquivo de XML informado: \"" + arquivoXml + "\" não encontrado."); //Verifica se o arquivo de schema foi encontrado. if (!File.Exists(arquivoSchema)) throw new Exception("Arquivo de schema: \"" + arquivoSchema + "\" não encontrado."); // Cria um novo XMLValidatingReader var reader = new XmlValidatingReader(new XmlTextReader(new StreamReader(arquivoXml))); // Cria um schemacollection var schemaCollection = new XmlSchemaCollection(); //Adiciona o XSD e o namespace schemaCollection.Add("http://www.portalfiscal.inf.br/nfe", arquivoSchema); // Adiciona o schema ao ValidatingReader reader.Schemas.Add(schemaCollection); //Evento que retorna a mensagem de validacao reader.ValidationEventHandler += Reader_ValidationEventHandler; //Percorre o XML while (reader.Read()) { } reader.Close(); //Fecha o arquivo. //O Resultado é preenchido no reader_ValidationEventHandler if (validarResultado != "") { throw new Exception(validarResultado); } }
private string consultaNFe() { XmlSchemaCollection myschema = new XmlSchemaCollection(); string sxdoc = ""; XNamespace pf = "http://www.portalfiscal.inf.br/nfe"; try { XDocument xdoc = new XDocument(new XElement(pf + "consSitNFe", new XAttribute("versao", sversaoLayoutCons),//sversaoLayoutCons), new XElement(pf + "tpAmb", Acesso.TP_AMB.ToString()), new XElement(pf + "xServ", "CONSULTAR"), new XElement(pf + "chNFe", objPesquisa.sCHAVENFE))); string sCaminhoConsulta = Pastas.PROTOCOLOS + "Consulta_" + objPesquisa.sCHAVENFE + ".xml"; if (File.Exists(sCaminhoConsulta)) { File.Delete(sCaminhoConsulta); } StreamWriter writer = new StreamWriter(sCaminhoConsulta); writer.Write(xdoc.ToString()); writer.Close(); //belValidaXml.ValidarXml("http://www.portalfiscal.inf.br/nfe", Pastas.SCHEMA_NFE + "\\2.01\\consSitNFe_v2.01.xsd", sCaminhoConsulta); sxdoc = xdoc.ToString(); } catch (XmlException x) { throw new Exception(x.Message.ToString()); } catch (XmlSchemaException x) { throw new Exception(x.Message.ToString()); } return sxdoc; }
public void TestAddDoesCompilation () { XmlSchema schema = new XmlSchema (); Assert (!schema.IsCompiled); XmlSchemaCollection col = new XmlSchemaCollection (); col.Add (schema); Assert (schema.IsCompiled); }
public clsSValidator(string sXMLFileName, string sSchemaFileName) { m_sXMLFileName = sXMLFileName; m_sSchemaFileName = sSchemaFileName; m_objXmlSchemaCollection = new XmlSchemaCollection (); //adding the schema file to the newly created schema collection m_objXmlSchemaCollection.Add (null, m_sSchemaFileName); }
public NSTScorePartwise ParseString(string dataString) { //todo: parse string IList<NSTPart> partList = new List<NSTPart>(); XmlTextReader textReader = new XmlTextReader(new FileStream("C:\\NM\\ScoreTranscription\\NETScoreTranscription\\NETScoreTranscriptionLibrary\\OtherDocs\\musicXML.xsd", System.IO.FileMode.Open)); //todo: pass stream in instead of absolute location for unit testing XmlSchemaCollection schemaCollection = new XmlSchemaCollection(); schemaCollection.Add(null, textReader); NSTScorePartwise score; using (XmlValidatingReader reader = new XmlValidatingReader(XmlReader.Create(new StringReader(dataString), new XmlReaderSettings() { DtdProcessing = DtdProcessing.Parse }))) //todo: make unobsolete { reader.Schemas.Add(schemaCollection); reader.ValidationType = ValidationType.Schema; reader.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(ValidationEventHandler); XmlSerializer serializer = new XmlSerializer(typeof(NSTScorePartwise), new XmlRootAttribute("score-partwise")); score = (NSTScorePartwise)serializer.Deserialize(reader); /* while (reader.Read()) { if (reader.IsEmptyElement) throw new Exception(reader.Value); //todo: test switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.Name.ToLower()) { case "part-list": break; case "score-partwise": break; case "part-name": throw new Exception("pn"); break; } break; case XmlNodeType.Text: break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: break; case XmlNodeType.Comment: break; case XmlNodeType.EndElement: break; } }*/ } return score; }
public BaseValidator(XmlValidatingReaderImpl reader, XmlSchemaCollection schemaCollection, IValidationEventHandling eventHandling) { this.reader = reader; this.schemaCollection = schemaCollection; this.eventHandling = eventHandling; this.nameTable = reader.NameTable; this.positionInfo = System.Xml.PositionInfo.GetPositionInfo(reader); this.elementName = new XmlQualifiedName(); }
/// <summary> /// Instantiate a new XmlSchemaCompiler class. /// </summary> /// <param name="outputDir">The output directory for all compiled files.</param> public XmlSchemaCompiler(string outputDir) { this.mainSchemas = new XmlSchemaCollection(); this.outputDir = outputDir; this.elements = new Hashtable(); this.attributes = new Hashtable(); this.schemas = new XmlSchemaCollection(); }
/// <summary> /// Instantiate a new XmlSchemaCompiler class. /// </summary> /// <param name="outputDir">The output directory for all compiled files.</param> /// <param name="versionNumber">The version number to append to Elements.</param> public XmlSchemaCompiler(string outputDir, string versionNumber) { this.outputDir = outputDir; this.versionNumber = versionNumber; this.elements = new Hashtable(); this.schemaFiles = new StringCollection(); this.schemas = new XmlSchemaCollection(); }
public BaseValidator(XmlValidatingReaderImpl reader, XmlSchemaCollection schemaCollection, IValidationEventHandling eventHandling) { Debug.Assert(schemaCollection == null || schemaCollection.NameTable == reader.NameTable); this.reader = reader; this.schemaCollection = schemaCollection; this.eventHandling = eventHandling; nameTable = reader.NameTable; positionInfo = PositionInfo.GetPositionInfo(reader); elementName = new XmlQualifiedName(); }
static void Main(string[] args) { if (args.Length != 4) { Console.WriteLine("Invalid parameter count. Exiting..."); return; } string xmlFile = args[0]; string xdsFile = args[1]; string xdsNamespace = args[2]; string outputFile = args[3]; try { XmlSchemaCollection cache = new XmlSchemaCollection(); cache.Add(xdsNamespace, xdsFile); XmlTextReader r = new XmlTextReader(xmlFile); XmlValidatingReader v = new XmlValidatingReader(r); v.Schemas.Add(cache); v.ValidationType = ValidationType.Schema; v.ValidationEventHandler += new ValidationEventHandler(MyValidationEventHandler); while (v.Read()) { } // look for validation errors v.Close(); } catch (Exception e) { encounteredFatalError = true; fatalError = e; } StreamWriter file = new StreamWriter(outputFile); if (isValid && !encounteredFatalError) file.WriteLine("PASSED: Document is valid"); else file.WriteLine("FAILED: Document is invalid"); // Printing foreach (string entry in list) { file.WriteLine(entry); } if (encounteredFatalError) { file.WriteLine("Error: a FATAL error has occured " + "while reading the file.\r\n" + fatalError.ToString()); } file.Close(); }
public BaseValidator(BaseValidator other) { reader = other.reader; schemaCollection = other.schemaCollection; eventHandling = other.eventHandling; nameTable = other.nameTable; schemaNames = other.schemaNames; positionInfo = other.positionInfo; xmlResolver = other.xmlResolver; baseUri = other.baseUri; elementName = other.elementName; }
public BaseValidator(BaseValidator other) { reader = other.reader; _schemaCollection = other._schemaCollection; _eventHandling = other._eventHandling; _nameTable = other._nameTable; _schemaNames = other._schemaNames; _positionInfo = other._positionInfo; _xmlResolver = other._xmlResolver; _baseUri = other._baseUri; elementName = other.elementName; }
public BaseValidator(BaseValidator other) { this.reader = other.reader; this.schemaCollection = other.schemaCollection; this.eventHandling = other.eventHandling; this.nameTable = other.nameTable; this.schemaNames = other.schemaNames; this.positionInfo = other.positionInfo; this.xmlResolver = other.xmlResolver; this.baseUri = other.baseUri; this.elementName = other.elementName; }
/// <summary> /// Gets an appropriate <see cref="System.Xml.XmlReader"/> implementation /// for the supplied <see cref="System.IO.Stream"/>. /// </summary> /// <param name="stream">The XML <see cref="System.IO.Stream"/> that is going to be read.</param> /// <param name="xmlResolver"><see cref="XmlResolver"/> to be used for resolving external references</param> /// <param name="schemas">XML schemas that should be used for validation.</param> /// <param name="eventHandler">Validation event handler.</param> /// <returns> /// A validating <see cref="System.Xml.XmlReader"/> implementation. /// </returns> public static XmlReader CreateValidatingReader(Stream stream, XmlResolver xmlResolver, XmlSchemaCollection schemas, ValidationEventHandler eventHandler) { XmlValidatingReader reader = new XmlValidatingReader(new XmlTextReader(stream)); reader.XmlResolver = xmlResolver; reader.Schemas.Add(schemas); reader.ValidationType = ValidationType.Schema; if (eventHandler != null) { reader.ValidationEventHandler += eventHandler; } return reader; }
private void Page_Load(object sender, System.EventArgs e) { XmlValidatingReader reader = null; XmlSchemaCollection myschema = new XmlSchemaCollection(); ValidationEventHandler eventHandler = new ValidationEventHandler(ShowCompileErrors ); try { String xmlFrag = @"<?xml version='1.0' ?> <item> <xxx:price xmlns:xxx='xxx' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='test.xsd'></xxx:price> </item>"; /*"<author xmlns='urn:bookstore-schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" + "<first-name>Herman</first-name>" + "<last-name>Melville</last-name>" + "</author>";*/ string xsd = @"<?xml version='1.0' encoding='UTF-8'?> <xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema' targetNamespace='xxx'> <xsd:element name='price' type='xsd:integer' xsd:default='12'/> </xsd:schema>"; //Create the XmlParserContext. XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None); //Implement the reader. reader = new XmlValidatingReader(xmlFrag, XmlNodeType.Element, context); //Add the schema. myschema.Add("xxx", new XmlTextReader(new StringReader(xsd))); //Set the schema type and add the schema to the reader. reader.ValidationType = ValidationType.Schema; reader.Schemas.Add(myschema); while (reader.Read()){Response.Write(reader.Value);} Response.Write("<br>Completed validating xmlfragment<br>"); } catch (XmlException XmlExp) { Response.Write(XmlExp.Message + "<br>"); } catch(XmlSchemaException XmlSchExp) { Response.Write(XmlSchExp.Message + "<br>"); } catch(Exception GenExp) { Response.Write(GenExp.Message + "<br>"); } finally {} XmlDocument doc; }
//[Variation(Desc = "v2 - Contains with not added schema")] public void v2() { XmlSchemaSet sc = new XmlSchemaSet(); #pragma warning disable 0618 XmlSchemaCollection scl = new XmlSchemaCollection(); #pragma warning restore 0618 XmlSchema Schema = scl.Add(null, TestData._XsdAuthor); Assert.Equal(sc.Contains(Schema), false); return; }
public void Validate(string strXMLDoc) { try { // Declare local objects XmlTextReader tr = null; XmlSchemaCollection xsc = null; XmlValidatingReader vr = null; // Text reader object tr = new XmlTextReader(Application.StartupPath + @"\BDOCImportSchema.xsd"); xsc = new XmlSchemaCollection(); xsc.Add(null, tr); // XML validator object vr = new XmlValidatingReader(strXMLDoc, XmlNodeType.Document, null); vr.Schemas.Add(xsc); // Add validation event handler vr.ValidationType = ValidationType.Schema; vr.ValidationEventHandler += new ValidationEventHandler(ValidationHandler); // Validate XML data while (vr.Read()) ; vr.Close(); // Raise exception, if XML validation fails if (ErrorsCount > 0) { throw new Exception(ErrorMessage); } // XML Validation succeeded Console.WriteLine("XML validation succeeded.\r\n"); } catch (Exception error) { // XML Validation failed Console.WriteLine("XML validation failed." + "\r\n" + "Error Message: " + error.Message); throw new Exception("Error in XSD verification:\r\n" + error.Message); } }
#pragma warning restore 618 static CodeFormatter() { //Load the schema collection. var resource = typeof (CodeFormatter) .Assembly .GetManifestResourceStream("Rsdn.Framework.Formatting.CodeFormat.Patterns.PatternSchema.xsd"); Debug.Assert(resource != null); #pragma warning disable 618 _xmlSchemas = new XmlSchemaCollection { XmlSchema.Read(resource, null) }; #pragma warning restore 618 }
protected override XmlValidatingReader GetReader() { if (LogDispatcher != null) LogDispatcher.DispatchLog("XSLTRulesFileDriver loading "+xmlSource, LogEventImpl.INFO); XmlReader fileReader = GetXmlInputReader(xmlSource, inputXMLSchema); MemoryStream stream = new MemoryStream(); GetXSLT().Transform(new XPathDocument(fileReader), null, stream, null); fileReader.Close(); stream.Seek(0, SeekOrigin.Begin); XmlSchemaCollection schemas = new XmlSchemaCollection(); XmlValidatingReader streamReader = (XmlValidatingReader) GetXmlInputReader(stream, Parameter.GetString("businessrules.xsd", "resource.businessRules.xsd")); return streamReader; }
public void Add(XmlSchemaCollection schema) { if (schema == null) { throw new ArgumentNullException("schema"); } if (this != schema) { IDictionaryEnumerator enumerator = schema.collection.GetEnumerator(); while (enumerator.MoveNext()) { XmlSchemaCollectionNode node = (XmlSchemaCollectionNode) enumerator.Value; this.Add(node.NamespaceURI, node); } } }
/// <summary> /// Validates the specified xml content /// </summary> /// <param name="sImportDocument">Xml content to validate</param> /// <returns>Error messages if any, else "true"</returns> public List<string> ValidateCrmImportDocument(string sImportDocument) { ValidationEventHandler eventHandler = ShowCompileErrors; XmlSchemaCollection myschemacoll = new XmlSchemaCollection(); XmlValidatingReader vr; try { using (StreamReader schemaReader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("MsCrmTools.SiteMapEditor.Resources.sitemap.xsd"))) { //Load the XmlValidatingReader. vr = new XmlValidatingReader(schemaReader.BaseStream, XmlNodeType.Element, null); vr.Schemas.Add(myschemacoll); vr.ValidationType = ValidationType.Schema; while (vr.Read()) { } } return messages; } //This code catches any XML exceptions. catch (XmlException XmlExp) { messages.Add(XmlExp.Message); return messages; } //This code catches any XML schema exceptions. catch (XmlSchemaException XmlSchemaExp) { messages.Add(XmlSchemaExp.Message); return messages; } //This code catches any standard exceptions. catch (Exception GeneralExp) { messages.Add(GeneralExp.Message); return messages; } finally { vr = null; myschemacoll = null; } }
public static void ValidateXml(Stream xmlStream, XmlSchema xsdSchema) { XmlTextReader reader1 = null; try { reader1 = new XmlTextReader(xmlStream); XmlSchemaCollection collection1 = new XmlSchemaCollection(); collection1.Add(xsdSchema); XmlValidatingReader reader2 = new XmlValidatingReader(reader1); reader2.ValidationType = ValidationType.Schema; reader2.Schemas.Add(collection1); ArrayList list1 = new ArrayList(); while (reader2.ReadState != ReadState.EndOfFile) { try { reader2.Read(); continue; } catch (XmlSchemaException exception1) { list1.Add(exception1); continue; } } if (list1.Count != 0) { throw new XmlValidationException(list1); } } catch (XmlValidationException exception2) { throw exception2; } catch (Exception exception3) { throw new XmlValidationException(exception3.Message, exception3); } finally { if (reader1 != null) { reader1.Close(); } } }
public SchemaValidator(string xmlFile, string schemaFile) { XmlSchemaCollection myXmlSchemaCollection = new XmlSchemaCollection(); XmlTextReader xmlTextReader = new XmlTextReader(schemaFile); try { myXmlSchemaCollection.Add(XmlSchema.Read(xmlTextReader, null)); } finally { xmlTextReader.Close(); } // Validate the XML file with the schema XmlTextReader myXmlTextReader = new XmlTextReader (xmlFile); myXmlValidatingReader = new XmlValidatingReader(myXmlTextReader); myXmlValidatingReader.Schemas.Add(myXmlSchemaCollection); myXmlValidatingReader.ValidationType = ValidationType.Schema; }
public PcaCompiler() { try { Assembly assembly = Assembly.GetExecutingAssembly(); // read schema using (Stream s = assembly.GetManifestResourceStream("Microsoft.Tools.WindowsInstallerXml.Xsd.pubca.xsd")) { this.xmlSchema = XmlSchema.Read(s, null); } // read table definitions using (Stream s = assembly.GetManifestResourceStream("Microsoft.Tools.WindowsInstallerXml.Data.tables.xml")) { XmlReader tableDefinitionsReader = new XmlTextReader(s); #if DEBUG Assembly wixAssembly = Assembly.GetAssembly(typeof(Compiler)); using (Stream schemaStream = wixAssembly.GetManifestResourceStream("Microsoft.Tools.WindowsInstallerXml.Xsd.tables.xsd")) { XmlReader schemaReader = new XmlTextReader(schemaStream); XmlSchemaCollection schemas = new XmlSchemaCollection(); schemas.Add("http://schemas.microsoft.com/wix/2003/04/tables", schemaReader); XmlValidatingReader validatingReader = new XmlValidatingReader(tableDefinitionsReader); validatingReader.Schemas.Add(schemas); tableDefinitionsReader = validatingReader; } #endif this.tableDefinitionCollection = TableDefinitionCollection.Load(tableDefinitionsReader); tableDefinitionsReader.Close(); } } catch (Exception e) { Debug.WriteLine(e.ToString()); System.Console.WriteLine(e.ToString()); throw; } }
private string NfeCabecMsg() { XmlSchemaCollection myschema = new XmlSchemaCollection(); XmlValidatingReader reader; try { XNamespace nome = "http://www.portalfiscal.inf.br/nfe"; XDocument xdoc = new XDocument(new XElement(nome + "cabecMsg", new XAttribute("versao", _pversao), new XAttribute("xmlns", "http://www.portalfiscal.inf.br/nfe"), new XElement(nome + "versaoDados", _pversaoaplic))); //Danner - o.s. sem - 04/11/2009 // Globais getschema = new Globais(); // XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None); // reader = new XmlValidatingReader(xdoc.ToString(), XmlNodeType.Element, context); //myschema.Add("http://www.portalfiscal.inf.br/nfe", getschema.LeRegWin("PastaSchema") + "\\cabecMsg_v1.02.xsd"); //reader.ValidationType = ValidationType.Schema; // reader.Schemas.Add(myschema); // while (reader.Read()) // { } return xdoc.ToString(); } catch (XmlException x) { throw new Exception(x.Message.ToString()); } catch (XmlSchemaException x) { throw new Exception(x.Message.ToString()); } //Fim - Danner - o.s. sem - 04/11/2009 }
public static BaseValidator CreateInstance(ValidationType valType, XmlValidatingReaderImpl reader, XmlSchemaCollection schemaCollection, IValidationEventHandling eventHandling, bool processIdentityConstraints) { switch (valType) { case ValidationType.None: return new BaseValidator(reader, schemaCollection, eventHandling); case ValidationType.Auto: return new AutoValidator(reader, schemaCollection, eventHandling); case ValidationType.DTD: return new DtdValidator(reader, eventHandling, processIdentityConstraints); case ValidationType.XDR: return new XdrValidator(reader, schemaCollection, eventHandling); case ValidationType.Schema: return new XsdValidator(reader, schemaCollection, eventHandling); } return null; }
/// <summary> /// This is where the work is done. /// </summary> protected override void ExecuteTask() { XmlSchemaCollection schemaCollection = new XmlSchemaCollection(); foreach (XmlSchemaReference schema in Schemas) { try { schemaCollection.Add(schema.Namespace, schema.Source); } catch (XmlSchemaException ex) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Invalid XSD schema '{0}.", schema.Source), Location, ex); } } foreach (string file in XmlFiles.FileNames) { // initialize error counter _numErrors = 0; // output name of xml file that will be validated Log(Level.Info, "Validating '{0}'.", file); try { ValidateFile(file, schemaCollection); } catch (XmlException ex) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Invalid XML file '{0}'.", file), Location, ex); } if (_numErrors == 0) { Log(Level.Info, "Document is valid."); } else { if (!FailOnError) { Log(Level.Info, "{0} validation errors in document.", _numErrors); } else { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "XML validation failed for document '{0}'.", file), Location); } } } }
public static BaseValidator CreateInstance(ValidationType valType, XmlValidatingReaderImpl reader, XmlSchemaCollection schemaCollection, IValidationEventHandling eventHandling, bool processIdentityConstraints) { switch (valType) { case ValidationType.None: return(new BaseValidator(reader, schemaCollection, eventHandling)); case ValidationType.Auto: return(new AutoValidator(reader, schemaCollection, eventHandling)); case ValidationType.DTD: return(new DtdValidator(reader, eventHandling, processIdentityConstraints)); case ValidationType.XDR: return(new XdrValidator(reader, schemaCollection, eventHandling)); case ValidationType.Schema: return(new XsdValidator(reader, schemaCollection, eventHandling)); } return(null); }
public AutoValidator(XmlValidatingReaderImpl reader, XmlSchemaCollection schemaCollection, IValidationEventHandling eventHandling) : base(reader, schemaCollection, eventHandling) { schemaInfo = new SchemaInfo(); }
private void LoadExternals(XmlSchemaCollection schemaCollection, XmlNameTable nameTable, SchemaNames schemaNames, ValidationEventHandler validationEventHandler, XmlSchema schema) { foreach (XmlSchemaExternal include in schema.Includes) { string fullPath = null; if (include.Schema != null) { // already loaded fullPath = include.FullPath; if (fullPath != null) { this.schemaLocations.Add(fullPath, fullPath); } LoadExternals(schemaCollection, nameTable, schemaNames, validationEventHandler, include.Schema); continue; } string schemaLocation = include.SchemaLocation; if (schemaCollection != null && include is XmlSchemaImport) { include.Schema = schemaCollection[((XmlSchemaImport)include).Namespace]; if (include.Schema != null) { include.Schema = include.Schema.Clone(); continue; } } if (include is XmlSchemaImport && ((XmlSchemaImport)include).Namespace == XmlReservedNs.NsXml) { if (!buildinIncluded) { buildinIncluded = true; include.Schema = GetBuildInSchema(nameTable); } continue; } if (schemaLocation == null) { continue; } Stream stream = ResolveSchemaLocation(schema, schemaLocation, out fullPath); if (stream != null) { include.FullPath = fullPath; if (this.schemaLocations[fullPath] == null) { this.schemaLocations.Add(fullPath, fullPath); XmlTextReader reader = new XmlTextReader(fullPath, stream, nameTable); try { reader.XmlResolver = new XmlUrlResolver(); include.Schema = new Parser(schemaCollection, nameTable, schemaNames, validationEventHandler).Parse(reader, null, null); while (reader.Read()) { ; // wellformness check } this.errorCount += include.Schema.ErrorCount; LoadExternals(schemaCollection, nameTable, schemaNames, validationEventHandler, include.Schema); } catch (XmlSchemaException e) { if (validationEventHandler != null) { validationEventHandler(null, new ValidationEventArgs( new XmlSchemaException(Res.Sch_CannotLoadSchema, new string[] { schemaLocation, e.Message }), XmlSeverityType.Error )); } } catch (Exception) { if (validationEventHandler != null) { validationEventHandler(null, new ValidationEventArgs( new XmlSchemaException(Res.Sch_InvalidIncludeLocation, include), XmlSeverityType.Warning )); } } finally { reader.Close(); } } else { stream.Close(); } } else { if (validationEventHandler != null) { validationEventHandler(null, new ValidationEventArgs( new XmlSchemaException(Res.Sch_InvalidIncludeLocation, include), XmlSeverityType.Warning )); } } } }
internal XsdValidator(XmlValidatingReaderImpl reader, XmlSchemaCollection schemaCollection, IValidationEventHandling eventHandling) : base(reader, schemaCollection, eventHandling) { this.startIDConstraint = -1; this.Init(); }
/// <summary> /// Gera a Estrutura do XML da NF-e /// </summary> /// <param name="sNF"></param> /// <param name="cert"></param> /// <param name="sEmp"></param> /// <param name="sNomeArq"></param> /// <param name="iStatusAtualSistema"</param> public void geraArquivoNFE(List<string> sNF, X509Certificate2 cert, string sEmp, string sNomeArq) { objbelGeraXml = new belGerarXML(); Conn = objbelGeraXml.Conn; Conn.Open(); try { string sPath = ""; sPath = (sFormaEmiNFe.Equals("2") ? CarregarDadosXml("PastaContingencia").ToString() + @sNomeArq : CarregarDadosXml("PastaXmlEnvio").ToString() + @sNomeArq); Globais glob = new Globais(); int iCount = 0; if (File.Exists(sPath)) { File.Delete(sPath); } foreach (var i in lTotNota) { string sNota = sNF[iCount]; string sNFe = "NFe" + GeraChave(sEmp, sNota, Conn); XDocument xdoc = new XDocument(); #region XML_Principal XNamespace pf = "http://www.portalfiscal.inf.br/nfe"; XContainer conenv = new XElement(pf + "enviNFe", new XAttribute("xmlns", "http://www.portalfiscal.inf.br/nfe"), new XAttribute("versao", "2.00"), new XElement(pf + "idLote", sNomeArq.Substring(7, 15))); #endregion #region XML_Cabeçalho XContainer concabec = (new XElement(pf + "NFe", new XAttribute("xmlns", "http://www.portalfiscal.inf.br/nfe"))); XContainer coninfnfe = (new XElement(pf + "infNFe", new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"), new XAttribute("Id", sNFe), new XAttribute("versao", "2.00"))); #endregion #region Ide XContainer conide; try { belIde objide = i[0] as belIde; #region XML_ide conide = (new XElement(pf + "ide", new XElement(pf + "cUF", objide.Cuf.ToString()), new XElement(pf + "cNF", objide.Cnf.ToString()), new XElement(pf + "natOp", objide.Natop.ToString()), new XElement(pf + "indPag", objide.Indpag.ToString()), new XElement(pf + "mod", objide.Mod.ToString()), new XElement(pf + "serie", objide.Serie.ToString()), new XElement(pf + "nNF", objide.Nnf.ToString()), new XElement(pf + "dEmi", objide.Demi.ToString("yyyy-MM-dd")), new XElement(pf + "dSaiEnt", objide.Dsaient.ToString("yyyy-MM-dd")), new XElement(pf + "hSaiEnt", objide.HSaiEnt.ToString("HH:mm:ss")), // NFe_2.0 new XElement(pf + "tpNF", objide.Tpnf.ToString()), new XElement(pf + "cMunFG", objide.Cmunfg.ToString()), (objide.belNFref != null ? (from c in objide.belNFref select new XElement(pf + "NFref", (c.RefNFe != null ? new XElement(pf + "refNFe", c.RefNFe) : null), (c.cUF != null ? (new XElement(pf + "refNF", (c.cUF != null ? new XElement(pf + "cUF", c.cUF) : null), (c.AAMM != null ? new XElement(pf + "AAMM", c.AAMM) : null), (c.CNPJ != null ? new XElement(pf + "CNPJ", c.CNPJ) : null), (c.mod != null ? new XElement(pf + "mod", c.mod) : null), (c.serie != null ? new XElement(pf + "serie", c.serie) : null), (c.nNF != null ? new XElement(pf + "nNF", c.nNF) : null))) : null))) : null),//NFe_2.0_Verificar ID B14 - B20a - B20i - new XElement(pf + "tpImp", objide.Tpimp.ToString()), new XElement(pf + "tpEmis", objide.Tpemis.ToString()), new XElement(pf + "cDV", objide.Cdv.ToString()), new XElement(pf + "tpAmb", objide.Tpamb.ToString()), new XElement(pf + "finNFe", objide.Finnfe.ToString()), new XElement(pf + "procEmi", objide.Procemi.ToString()), new XElement(pf + "verProc", objide.Verproc.ToString()), ((objide.Tpemis.Equals("2")) || (objide.Tpemis.Equals("3")) ? new XElement(pf + "dhCont", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss")) : null), // NFe_2.0 ((objide.Tpemis.Equals("2")) || (objide.Tpemis.Equals("3")) ? new XElement(pf + "xJust", (iStatusAtualSistema == 2 ? "FALHA DE CONEXÃO COM INTERNET" : "FALHA COM WEB SERVICE DO ESTADO")) : null)));// NFe_2.0 #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_ide - " + x.Message); } #endregion #region Emit XContainer conemit; try { belEmit objemit = i[1] as belEmit; #region XML_Emit conemit = (new XElement(pf + "emit", (new XElement(pf + "CNPJ", objemit.Cnpj.ToString())), new XElement(pf + "xNome", objemit.Xnome.ToString()), new XElement(pf + "xFant", objemit.Xfant.ToString()), new XElement(pf + "enderEmit", new XElement(pf + "xLgr", objemit.Xlgr.ToString()), new XElement(pf + "nro", objemit.Nro.ToString()), (objemit.Xcpl != null ? new XElement(pf + "xCpl", objemit.Xcpl.ToString()) : null), new XElement(pf + "xBairro", objemit.Xbairro.ToString()), new XElement(pf + "cMun", objemit.Cmun.ToString()), new XElement(pf + "xMun", objemit.Xmun.ToString()), new XElement(pf + "UF", objemit.Uf.ToString()), new XElement(pf + "CEP", objemit.Cep.ToString()), new XElement(pf + "cPais", objemit.Cpais.ToString()), new XElement(pf + "xPais", objemit.Xpais.ToString()), (objemit.Fone != null ? new XElement(pf + "fone", objemit.Fone.ToString()) : null)), (objemit.Ie != null ? new XElement(pf + "IE", objemit.Ie.ToString()) : null), (objemit.Iest != null ? new XElement(pf + "IEST", objemit.Iest.ToString()) : null), (objemit.Im != null ? new XElement(pf + "IM", objemit.Im.ToString()) : null), (objemit.Cnae != null ? new XElement(pf + "CNAE", objemit.Cnae.ToString()) : null), new XElement(pf + "CRT", objemit.CRT.ToString()))); // NFe_2.0 #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Emit - " + x.Message); } #endregion #region Dest XContainer condest; try { belDest objdest = i[2] as belDest; #region XML_Dest objdest.Ie = (objdest.Ie == null ? "" : objdest.Ie); condest = (new XElement(pf + "dest", (objdest.Cnpj == "EXTERIOR" ? new XElement(pf + "CNPJ") : (objdest.Cnpj != null ? new XElement(pf + "CNPJ", objdest.Cnpj) : new XElement(pf + "CPF", objdest.Cpf))), new XElement(pf + "xNome", objdest.Xnome.ToString()), new XElement(pf + "enderDest", new XElement(pf + "xLgr", objdest.Xlgr.ToString()), new XElement(pf + "nro", (objdest.Nro != null ? objdest.Nro.ToString() : "0")), (objdest.Xcpl != null ? new XElement(pf + "xCpl", objdest.Xcpl.ToString()) : null), new XElement(pf + "xBairro", objdest.Xbairro.ToString()), new XElement(pf + "cMun", objdest.Cmun.ToString()), new XElement(pf + "xMun", objdest.Xmun.ToString()), new XElement(pf + "UF", objdest.Uf.ToString()), (objdest.Cep != null ? new XElement(pf + "CEP", objdest.Cep.ToString()) : null), new XElement(pf + "cPais", objdest.Cpais.ToString()), (objdest.Xpais != null ? new XElement(pf + "xPais", objdest.Xpais.ToString()) : null), (objdest.Fone != null ? new XElement(pf + "fone", objdest.Fone.ToString()) : null)), ((objdest.Ie != null) ? (objdest.Ie != "EXTERIOR" ? new XElement(pf + "IE", objdest.Ie.ToString()) : new XElement(pf + "IE")) : null), //Claudinei - o.s. sem - 11/02/2010 (objdest.Isuf != null ? new XElement(pf + "ISUF", objdest.Isuf.ToString()) : null))); #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Dest - " + x.Message); } #endregion #region Det List<XElement> lcondet = new List<XElement>(); try { List<belDet> objdet = new List<belDet>(); objdet = i[4] as List<belDet>; #region XML_Detalhes foreach (var det in objdet) { XElement condet = (new XElement(pf + "det", new XAttribute("nItem", det.Nitem), new XElement(pf + "prod", (det.belProd.Cprod != null ? new XElement(pf + "cProd", det.belProd.Cprod.ToString()) : null), (det.belProd.Cean != null ? new XElement(pf + "cEAN", det.belProd.Cean.ToString()) : null), (det.belProd.Xprod != null ? new XElement(pf + "xProd", det.belProd.Xprod.ToString()) : null), (det.belProd.Ncm != null ? new XElement(pf + "NCM", det.belProd.Ncm.ToString()) : new XElement(pf + "NCM", det.belProd.Ncm = "00000000")), //Claudinei - o.s. 24200 - 01/03/2010 (det.belProd.Extipi != null ? new XElement(pf + "EXTIPI", det.belProd.Extipi.ToString()) : null), (det.belProd.Genero != null ? new XElement(pf + "genero", det.belProd.Genero.ToString()) : null), (det.belProd.Cfop != null ? new XElement(pf + "CFOP", det.belProd.Cfop.ToString()) : null), (det.belProd.Ucom != null ? new XElement(pf + "uCom", det.belProd.Ucom.ToString()) : null), (det.belProd.Qcom != null ? new XElement(pf + "qCom", det.belProd.Qcom.ToString("#0.0000").Replace(",", ".")) : null), (det.belProd.Vuncom != null ? new XElement(pf + "vUnCom", det.belProd.Vuncom.ToString("#0.0000").Replace(",", ".")) : null), (det.belProd.Vprod != null ? new XElement(pf + "vProd", det.belProd.Vprod.ToString("#0.00").Replace(",", ".")) : null), (det.belProd.Ceantrib != null ? new XElement(pf + "cEANTrib", det.belProd.Ceantrib.ToString().PadLeft(8, '0')) : null), (det.belProd.Utrib != null ? new XElement(pf + "uTrib", det.belProd.Utrib.ToString()) : null), (det.belProd.Qtrib != null ? new XElement(pf + "qTrib", det.belProd.Qtrib.ToString("#0.0000").Replace(",", ".")) : null), (det.belProd.Vuntrib != null ? new XElement(pf + "vUnTrib", det.belProd.Vuntrib.ToString("#0.0000").Replace(",", ".")) : null), ((det.belProd.Vfrete != null) && (det.belProd.Vfrete != 0) ? new XElement(pf + "vFrete", det.belProd.Vfrete.ToString("#0.00").Replace(",", ".")) : null), ((det.belProd.Vseg != null) && (det.belProd.Vseg != 0) ? new XElement(pf + "vSeg", det.belProd.Vseg.ToString("#0.00").Replace(",", ".")) : null), (((det.belProd.Vdesc != null) && (det.belProd.Vdesc != 0)) ? new XElement(pf + "vDesc", det.belProd.Vdesc.ToString("#0.00").Replace(",", ".")) : null), ((det.belProd.VOutro != null) && (det.belProd.VOutro != 0) ? new XElement(pf + "vOutro", det.belProd.VOutro.ToString("#0.00").Replace(",", ".")) : null), //NFe_2.0 (det.belProd.IndTot != null) ? new XElement(pf + "indTot", det.belProd.IndTot.ToString()) : null), //NFe_2.0 new XElement(pf + "imposto", //---------------ICMS-----------------// new XElement(pf + "ICMS", //-------------ICMS00-------------// (det.belImposto.belIcms.belIcms00 != null ? new XElement(pf + "ICMS00", (det.belImposto.belIcms.belIcms00.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms00.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms00.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms00.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms00.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms00.Modbc.ToString()) : null), (det.belImposto.belIcms.belIcms00.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms00.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms00.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms00.Picms.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms00.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms00.Vicms.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMS10-------------// (det.belImposto.belIcms.belIcms10 != null ? new XElement(pf + "ICMS10", (det.belImposto.belIcms.belIcms10.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms10.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms10.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms10.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms10.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms10.Modbc.ToString()) : null), (det.belImposto.belIcms.belIcms10.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms10.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms10.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms10.Picms.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms10.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms10.Vicms.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms10.Modbcst != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belIcms10.Modbcst.ToString()) : null), (det.belImposto.belIcms.belIcms10.Pmvast != 0 ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belIcms10.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. sem - 11/03/2010 (det.belImposto.belIcms.belIcms10.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belIcms10.Predbcst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms10.Vbcst != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belIcms10.Vbcst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms10.Picmsst != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belIcms10.Picmsst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms10.Vicmsst != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belIcms10.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMS20-------------// (det.belImposto.belIcms.belIcms20 != null ? new XElement(pf + "ICMS20", (det.belImposto.belIcms.belIcms20.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms20.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms20.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms20.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms20.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms20.Modbc.ToString()) : null), (det.belImposto.belIcms.belIcms20.Predbc != null ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belIcms20.Predbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms20.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms20.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms20.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms20.Picms.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms20.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms20.Vicms.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMS30-------------// (det.belImposto.belIcms.belIcms30 != null ? new XElement(pf + "ICMS30", (det.belImposto.belIcms.belIcms30.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms30.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms30.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms30.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms30.Modbcst != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belIcms30.Modbcst.ToString()) : null), (det.belImposto.belIcms.belIcms30.Pmvast != 0 ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belIcms30.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. sem - 12/03/2010 (det.belImposto.belIcms.belIcms30.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belIcms30.Predbcst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms30.Vbcst != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belIcms30.Vbcst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms30.Picmsst != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belIcms30.Picmsst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms30.Vicmsst != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belIcms30.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMS40-------------// (det.belImposto.belIcms.belIcms40 != null ? new XElement(pf + "ICMS40", (det.belImposto.belIcms.belIcms40.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms40.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms40.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms40.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms40.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms40.Vicms.ToString()) : null), //NFe_2.0 (det.belImposto.belIcms.belIcms40.motDesICMS != null ? new XElement(pf + "motDesICMS", det.belImposto.belIcms.belIcms40.motDesICMS.ToString()) : null)) : null),//NFe_2.0 //-------------ICMS41-------------// (det.belImposto.belIcms.belIcms41 != null ? new XElement(pf + "ICMS41", (det.belImposto.belIcms.belIcms41.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms41.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms41.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms41.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms41.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms41.Vicms.ToString()) : null),//NFe_2.0 (det.belImposto.belIcms.belIcms41.motDesICMS != null ? new XElement(pf + "motDesICMS", det.belImposto.belIcms.belIcms41.motDesICMS.ToString()) : null)) : null),//NFe_2.0 //-------------ICMS50-------------// (det.belImposto.belIcms.belIcms50 != null ? new XElement(pf + "ICMS50", (det.belImposto.belIcms.belIcms50.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms50.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms50.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms50.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms50.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms50.Vicms.ToString()) : null),//NFe_2.0 (det.belImposto.belIcms.belIcms50.motDesICMS != null ? new XElement(pf + "motDesICMS", det.belImposto.belIcms.belIcms50.motDesICMS.ToString()) : null)) : null),//NFe_2.0 //-------------ICMS51-------------// (det.belImposto.belIcms.belIcms51 != null ? new XElement(pf + "ICMS51", (det.belImposto.belIcms.belIcms51.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms51.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms51.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms51.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms51.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms51.Modbc.ToString()) : null), (det.belImposto.belIcms.belIcms51.Predbc != null ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belIcms51.Predbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms51.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms51.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms51.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms51.Picms.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms51.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms51.Vicms.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMS60-------------// (det.belImposto.belIcms.belIcms60 != null ? new XElement(pf + "ICMS60",//Danner - o.s. sem - 12/03/2010 (det.belImposto.belIcms.belIcms60.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms60.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms60.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms60.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms60.Vbcst != null ? new XElement(pf + "vBCSTRet", det.belImposto.belIcms.belIcms60.Vbcst.ToString("#0.00").Replace(",", ".")) : null),//NFe_2.0 - Mudança de nome de Tag (det.belImposto.belIcms.belIcms60.Vicmsst != null ? new XElement(pf + "vICMSSTRet", det.belImposto.belIcms.belIcms60.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null),//NFe_2.0 Mudança de nome de Tag //-------------ICMS70-------------// (det.belImposto.belIcms.belIcms70 != null ? new XElement(pf + "ICMS70", (det.belImposto.belIcms.belIcms70.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms70.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms70.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms70.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms70.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms70.Modbc.ToString()) : null), (det.belImposto.belIcms.belIcms70.Predbc != null ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belIcms70.Predbc.ToString("#0.00").Replace(',', '.')) : null), //Danner - o.s. 24091 - 06/02/2010 (det.belImposto.belIcms.belIcms70.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms70.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms70.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms70.Picms.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms70.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms70.Vicms.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms70.Modbcst != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belIcms70.Modbcst.ToString()) : null), (det.belImposto.belIcms.belIcms70.Pmvast != 0 ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belIcms70.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. sem - 12/03/2010 (det.belImposto.belIcms.belIcms70.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belIcms70.Predbcst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms70.Vbcst != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belIcms70.Vbcst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms70.Picmsst != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belIcms70.Picmsst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms70.Vicmsst != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belIcms70.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMS90-------------// (det.belImposto.belIcms.belIcms90 != null ? new XElement(pf + "ICMS90", (det.belImposto.belIcms.belIcms90.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms90.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms90.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms90.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms90.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms90.Modbc.ToString()) : null), (det.belImposto.belIcms.belIcms90.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms90.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms90.Predbc != 0 ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belIcms90.Predbc.ToString("#0.00").Replace(',', '.')) : null), //Danner - o.s. 24091 - 06/02/2010 //Claudinei - o.s. sem - 24/02/2010 (det.belImposto.belIcms.belIcms90.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms90.Picms.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms90.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms90.Vicms.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms90.Modbcst != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belIcms90.Modbcst.ToString()) : null), (det.belImposto.belIcms.belIcms90.Pmvast != 0 ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belIcms90.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. 24076 - 01/02/2010 (det.belImposto.belIcms.belIcms90.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belIcms90.Predbcst.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. 24076 - 01/02/2010 (det.belImposto.belIcms.belIcms90.Vbcst != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belIcms90.Vbcst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms90.Picmsst != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belIcms90.Picmsst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms90.Vicmsst != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belIcms90.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMSSN101--------------// (det.belImposto.belIcms.belICMSSN101 != null ? new XElement(pf + "ICMSSN101", (det.belImposto.belIcms.belICMSSN101.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN101.orig.ToString()) : null), new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN101.CSOSN.ToString()), (det.belImposto.belIcms.belICMSSN101.pCredSN != null ? new XElement(pf + "pCredSN", det.belImposto.belIcms.belICMSSN101.pCredSN.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belICMSSN101.vCredICMSSN != null ? new XElement(pf + "vCredICMSSN", det.belImposto.belIcms.belICMSSN101.vCredICMSSN.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMSSN102--------------// (det.belImposto.belIcms.belICMSSN102 != null ? new XElement(pf + "ICMSSN102", (det.belImposto.belIcms.belICMSSN102.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN102.orig.ToString()) : null), new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN102.CSOSN.ToString())) : null), //-------------ICMSSN201--------------// (det.belImposto.belIcms.belICMSSN201 != null ? new XElement(pf + "ICMSSN201", (det.belImposto.belIcms.belICMSSN201.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN201.orig.ToString()) : null), new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN201.CSOSN.ToString()), (det.belImposto.belIcms.belICMSSN201.modBCST != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belICMSSN201.modBCST.ToString()) : null), (det.belImposto.belIcms.belICMSSN201.pMVAST != null ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belICMSSN201.pMVAST.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belICMSSN201.pRedBCST != null ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belICMSSN201.pRedBCST.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belICMSSN201.vBCST != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belICMSSN201.vBCST.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belICMSSN201.pICMSST != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belICMSSN201.pICMSST.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belICMSSN201.vICMSST != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belICMSSN201.vICMSST.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belICMSSN201.pCredSN != null ? new XElement(pf + "pCredSN", det.belImposto.belIcms.belICMSSN201.pCredSN.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belICMSSN201.vCredICMSSN != null ? new XElement(pf + "vCredICMSSN", det.belImposto.belIcms.belICMSSN201.vCredICMSSN.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMSSN500--------------// (det.belImposto.belIcms.belICMSSN500 != null ? new XElement(pf + "ICMSSN500", (det.belImposto.belIcms.belICMSSN500.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN500.orig.ToString()) : null), new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN500.CSOSN.ToString()), (det.belImposto.belIcms.belICMSSN500.vBCSTRet != null ? new XElement(pf + "vBCSTRet", det.belImposto.belIcms.belICMSSN500.vBCSTRet.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belICMSSN500.vICMSSTRet != null ? new XElement(pf + "vICMSSTRet", det.belImposto.belIcms.belICMSSN500.vICMSSTRet.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMSSN900--------------// (det.belImposto.belIcms.belICMSSN900 != null ? new XElement(pf + "ICMSSN900", (det.belImposto.belIcms.belICMSSN900.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN900.orig.ToString()) : null), new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN900.CSOSN.ToString())) : null)), //(det.belImposto.belIcms.belICMSSN900.modBC != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belICMSSN900.modBC.ToString()) : null), //(det.belImposto.belIcms.belICMSSN900.vBC != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belICMSSN900.vBC.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.pRedBC != null ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belICMSSN900.pRedBC.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.pICMS != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belICMSSN900.pICMS.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.vICMS != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belICMSSN900.vICMS.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.modBCST != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belICMSSN900.modBCST.ToString()) : null), //(det.belImposto.belIcms.belICMSSN900.pMVAST != null ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belICMSSN900.pMVAST.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.pRedBCST != null ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belICMSSN900.pRedBCST.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.vBCST != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belICMSSN900.vBCST.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.pICMSST != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belICMSSN900.pICMSST.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.vICMSST != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belICMSSN900.vICMSST.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.vBCSTRet != null ? new XElement(pf + "vBCSTRet", det.belImposto.belIcms.belICMSSN900.vBCSTRet.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.vICMSSTRet != null ? new XElement(pf + "vICMSSTRet", det.belImposto.belIcms.belICMSSN900.vICMSSTRet.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.pCredSN != null ? new XElement(pf + "pCredSN", det.belImposto.belIcms.belICMSSN900.pCredSN.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.vCredICMSSN != null ? new XElement(pf + "vCredICMSSN", det.belImposto.belIcms.belICMSSN900.vCredICMSSN.ToString("#0.00").Replace(",", ".")) : null)) : null)), //---------------IPI-------------// (det.belImposto.belIpi != null ? new XElement(pf + "IPI", (det.belImposto.belIpi.Clenq != null ? new XElement(pf + "clEnq", det.belImposto.belIpi.Clenq.ToString()) : null), (det.belImposto.belIpi.Cnpjprod != null ? new XElement(pf + "CNPJProd", det.belImposto.belIpi.Cnpjprod.ToString()) : null), (det.belImposto.belIpi.Cselo != null ? new XElement(pf + "cSelo", det.belImposto.belIpi.Cselo.ToString()) : null), (det.belImposto.belIpi.Qselo != null ? new XElement(pf + "qSelo", det.belImposto.belIpi.Qselo.ToString()) : null), (det.belImposto.belIpi.Cenq != null ? new XElement(pf + "cEnq", det.belImposto.belIpi.Cenq.ToString()) : null), //-----------IPITrib-----------// (det.belImposto.belIpi.belIpitrib != null ? new XElement(pf + "IPITrib", (det.belImposto.belIpi.belIpitrib.Cst != null ? new XElement(pf + "CST", det.belImposto.belIpi.belIpitrib.Cst.ToString()) : null), (det.belImposto.belIpi.belIpitrib.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIpi.belIpitrib.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIpi.belIpitrib.Qunid != null ? new XElement(pf + "qUnid", det.belImposto.belIpi.belIpitrib.Qunid.ToString()) : null), (det.belImposto.belIpi.belIpitrib.Vunid != 0 ? new XElement(pf + "vUnid", det.belImposto.belIpi.belIpitrib.Vunid.ToString("#0.0000").Replace(",", ".")) : null), (det.belImposto.belIpi.belIpitrib.Pipi != null ? new XElement(pf + "pIPI", det.belImposto.belIpi.belIpitrib.Pipi.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIpi.belIpitrib.Vipi != null ? new XElement(pf + "vIPI", det.belImposto.belIpi.belIpitrib.Vipi.ToString("#0.00").Replace(",", ".")) : null)) : null), //-----------IPINT-----------// (det.belImposto.belIpi.belIpint != null ? new XElement(pf + "IPINT", (det.belImposto.belIpi.belIpint != null ? new XElement(pf + "CST", det.belImposto.belIpi.belIpint.Cst.ToString()) : null)) : null)) : null), //--------------II--------------// (det.belImposto.belIi != null ? new XElement(pf + "II", (det.belImposto.belIi.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIi.Vbc.ToString("#0.00").Replace(',', '.')) : null), (det.belImposto.belIi.Vdespadu != null ? new XElement(pf + "vDespAdu", det.belImposto.belIi.Vdespadu.ToString()) : null), (det.belImposto.belIi.Vii != null ? new XElement(pf + "vII", det.belImposto.belIi.Vii.ToString("0.00").Replace(',', '.')) : null), (det.belImposto.belIi.Viof != null ? new XElement(pf + "vIOF", det.belImposto.belIi.Viof.ToString("#0.00").Replace(',', '.')) : null)) : null), //----------------PIS------------// (det.belImposto.belPis != null ? new XElement(pf + "PIS", //-----------PISAliq----------// (det.belImposto.belPis.belPisaliq != null ? new XElement(pf + "PISAliq", (det.belImposto.belPis.belPisaliq.Cst != null ? new XElement(pf + "CST", det.belImposto.belPis.belPisaliq.Cst.ToString()) : null), (det.belImposto.belPis.belPisaliq.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belPis.belPisaliq.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belPis.belPisaliq.Ppis != null ? new XElement(pf + "pPIS", det.belImposto.belPis.belPisaliq.Ppis.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belPis.belPisaliq.Vpis != null ? new XElement(pf + "vPIS", det.belImposto.belPis.belPisaliq.Vpis.ToString("#0.00").Replace(",", ".")) : null)) : null), //-----------PISQtde-----------// (det.belImposto.belPis.belPisqtde != null ? new XElement(pf + "PISQtde", (det.belImposto.belPis.belPisqtde.Cst != null ? new XElement(pf + "CST", det.belImposto.belPis.belPisqtde.Cst.ToString()) : null), (det.belImposto.belPis.belPisqtde.Qbcprod != 0 ? new XElement(pf + "qBCProd", det.belImposto.belPis.belPisqtde.Qbcprod.ToString()) : null), (det.belImposto.belPis.belPisqtde.Valiqprod != null ? new XElement(pf + "vAliqProd", det.belImposto.belPis.belPisqtde.Valiqprod.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belPis.belPisqtde.Vpis != null ? new XElement(pf + "vPIS", det.belImposto.belPis.belPisqtde.Vpis.ToString("#0.00").Replace(",", ".")) : null)) : null), //----------PISNT------------// (det.belImposto.belPis.belPisnt != null ? new XElement(pf + "PISNT", (det.belImposto.belPis.belPisnt.Cst != null ? new XElement(pf + "CST", det.belImposto.belPis.belPisnt.Cst.ToString()) : null)) : null), //----------PISOutr-----------// (det.belImposto.belPis.belPisoutr != null ? new XElement(pf + "PISOutr", (det.belImposto.belPis.belPisoutr.Cst != null ? new XElement(pf + "CST", det.belImposto.belPis.belPisoutr.Cst.ToString()) : null), (det.belImposto.belPis.belPisoutr.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belPis.belPisoutr.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belPis.belPisoutr.Ppis != null ? new XElement(pf + "pPIS", det.belImposto.belPis.belPisoutr.Ppis.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belPis.belPisoutr.Qbcprod != 0 ? new XElement(pf + "qBCProd", det.belImposto.belPis.belPisoutr.Qbcprod.ToString()) : null), (det.belImposto.belPis.belPisoutr.Valiqprod != 0 ? new XElement(pf + "vAliqProd", det.belImposto.belPis.belPisoutr.Valiqprod.ToString("#0.0000").Replace(",", ".")) : null), (det.belImposto.belPis.belPisoutr.Vpis != null ? new XElement(pf + "vPIS", det.belImposto.belPis.belPisoutr.Vpis.ToString("#0.00").Replace(",", ".")) : null)) : null)) : null), //---------------COFINS---------------// (det.belImposto.belCofins != null ? new XElement(pf + "COFINS", //-----------COFINSAliq------------// (det.belImposto.belCofins.belCofinsaliq != null ? new XElement(pf + "COFINSAliq", new XElement(pf + "CST", det.belImposto.belCofins.belCofinsaliq.Cst.ToString()), new XElement(pf + "vBC", det.belImposto.belCofins.belCofinsaliq.Vbc.ToString("#0.00").Replace(",", ".")), new XElement(pf + "pCOFINS", det.belImposto.belCofins.belCofinsaliq.Pcofins.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vCOFINS", det.belImposto.belCofins.belCofinsaliq.Vcofins.ToString("#0.00").Replace(",", "."))) : null), //------------COFINSQtde------------// (det.belImposto.belCofins.belCofinsqtde != null ? new XElement(pf + "COFINSQtde", new XElement(pf + "CST", det.belImposto.belCofins.belCofinsqtde.Cst.ToString()), new XElement(pf + "pBCProd", det.belImposto.belCofins.belCofinsqtde.Qbcprod.ToString()), new XElement(pf + "vAliqProd", det.belImposto.belCofins.belCofinsqtde.Valiqprod.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vCOFINS", det.belImposto.belCofins.belCofinsqtde.Vcofins.ToString("#0.00").Replace(",", "."))) : null), //------------COFINSNT--------------// (det.belImposto.belCofins.belCofinsnt != null ? new XElement(pf + "COFINSNT", (det.belImposto.belCofins.belCofinsnt.Cst != null ? new XElement(pf + "CST", det.belImposto.belCofins.belCofinsnt.Cst.ToString()) : null)) : null), //------------COFINSOutr--------------// (det.belImposto.belCofins.belCofinsoutr != null ? new XElement(pf + "COFINSOutr", new XElement(pf + "CST", det.belImposto.belCofins.belCofinsoutr.Cst.ToString()), new XElement(pf + "vBC", det.belImposto.belCofins.belCofinsoutr.Vbc.ToString("#0.00").Replace(",", ".")), new XElement(pf + "pCOFINS", det.belImposto.belCofins.belCofinsoutr.Pcofins.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vCOFINS", det.belImposto.belCofins.belCofinsoutr.Vcofins.ToString("#0.00").Replace(",", "."))) : null)) : null), //----------------ISSQN-----------------// (det.belImposto.belIss != null ? new XElement(pf + "ISSQN", (det.belImposto.belIss.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIss.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIss.Valiq != null ? new XElement(pf + "vAliq", det.belImposto.belIss.Valiq.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIss.Vissqn != null ? new XElement(pf + "vISSQN", det.belImposto.belIss.Vissqn.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIss.Cmunfg != null ? new XElement(pf + "cMunFG", det.belImposto.belIss.Cmunfg.ToString()) : null), (det.belImposto.belIss.Clistserv != null ? new XElement(pf + "cListServ", det.belImposto.belIss.Clistserv.ToString()) : null), (det.belImposto.belIss.cSitTrib != null ? new XElement(pf + "cSitTrib", det.belImposto.belIss.cSitTrib.ToString()) : null)) : null)), // NFe_2.0 Tratar item //-----------INFADPROD-------------// (det.belInfadprod != null ? (det.belInfadprod.Infadprid != null ? new XElement(pf + "infAdProd", det.belInfadprod.Infadprid.ToString()) : null) : null))); //Danner - o.s. sem -21/12/2009 lcondet.Add(condet); } #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Detalhes - " + x.Message); } #endregion //Total XContainer contotal; try { belTotal objtotal = i[5] as belTotal; #region XML_Total contotal = (new XElement(pf + "total", (objtotal.belIcmstot != null ? new XElement(pf + "ICMSTot", new XElement(pf + "vBC", objtotal.belIcmstot.Vbc.ToString("#0.00").Replace(",", ".")),//Danner - o.s. 24271 - 15/03/2010 new XElement(pf + "vICMS", objtotal.belIcmstot.Vicms.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vBCST", objtotal.belIcmstot.Vbcst.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vST", objtotal.belIcmstot.Vst.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vProd", objtotal.belIcmstot.Vprod.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vFrete", objtotal.belIcmstot.Vfrete.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vSeg", objtotal.belIcmstot.Vseg.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vDesc", objtotal.belIcmstot.Vdesc.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vII", objtotal.belIcmstot.Vii.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vIPI", objtotal.belIcmstot.Vipi.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vPIS", objtotal.belIcmstot.Vpis.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vCOFINS", objtotal.belIcmstot.Vcofins.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vOutro", objtotal.belIcmstot.Voutro.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vNF", objtotal.belIcmstot.Vnf.ToString("#0.00").Replace(",", "."))) : null), (objtotal.belIssqntot != null ? new XElement(pf + "ISSQNtot", new XElement(pf + "vServ", objtotal.belIssqntot.Vserv.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vBC", objtotal.belIssqntot.Vbc.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vISS", objtotal.belIssqntot.Viss.ToString("#0.00").Replace(",", ".")), (objtotal.belIssqntot.Vpis != 0 ? new XElement(pf + "vPIS", objtotal.belIssqntot.Vpis.ToString("#0.00").Replace(",", ".")) : null), (objtotal.belIssqntot.Vcofins != 0 ? new XElement(pf + "vCOFINS", objtotal.belIssqntot.Vcofins.ToString("#0.00").Replace(",", ".")) : null)) : null))); //(objtotal.belRetTrib != null ? new XElement(pf + "retTrib", // new XElement(pf + "vRetPIS", objtotal.belRetTrib.Vretpis.ToString("#0.00").Replace(",", ".")), // new XElement(pf + "vRetCOFINS", objtotal.belRetTrib.Vretcofins.ToString("#0.00").Replace(",", ".")), // new XElement(pf + "vRetCSLL", objtotal.belRetTrib.Vretcsll.ToString("#0.00").Replace(",", ".")), // new XElement(pf + "vBCIRRF", objtotal.belRetTrib.Vbcirrf.ToString("#0.00"), // new XElement(pf + "vIRRF", objtotal.belRetTrib.Virrf.ToString("#0.00").Replace(",", ".")), // new XElement(pf + "vBCRetPrev", objtotal.belRetTrib.Vbcretprev.ToString("#0.00").Replace(",", ".")), // new XElement(pf + "vRetPrev", objtotal.belRetTrib.Vretprev.ToString("#0.00").Replace(",", "."))) : null))); #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Total - " + x.Message); } //Fim - Total //Frete XContainer contransp; belTransp objtransp; try { objtransp = i[6] as belTransp; #region XML_Transporte contransp = (new XElement(pf + "transp", new XElement(pf + "modFrete", objtransp.Modfrete.ToString()), new XElement(pf + "transporta", (objtransp.belTransportadora.Cnpj != null ? new XElement(pf + "CNPJ", objtransp.belTransportadora.Cnpj.ToString()) : (objtransp.belTransportadora.Cpf != null ? new XElement(pf + "CPF", objtransp.belTransportadora.Cpf.ToString()) : null)), (objtransp.belTransportadora.Xnome != null ? new XElement(pf + "xNome", objtransp.belTransportadora.Xnome.ToString()) : null), (objtransp.belTransportadora.Ie != null ? new XElement(pf + "IE", objtransp.belTransportadora.Ie.ToString()) : null), (objtransp.belTransportadora.Xender != null ? new XElement(pf + "xEnder", objtransp.belTransportadora.Xender.ToString()) : null), (objtransp.belTransportadora.Xmun != null ? new XElement(pf + "xMun", objtransp.belTransportadora.Xmun.ToString()) : null), (objtransp.belTransportadora.Uf != null ? new XElement(pf + "UF", objtransp.belTransportadora.Uf.ToString()) : null)), (objtransp.belRetTransp != null ? (new XElement(pf + "retTransp", new XElement(pf + "vServ", objtransp.belRetTransp.Vserv.ToString("#0.00").Replace(',', '.')), new XElement(pf + "vBCRet", objtransp.belRetTransp.Vbvret.ToString("#0.00").Replace(',', '.')), new XElement(pf + "pICMSRet", objtransp.belRetTransp.Picmsret.ToString()), new XElement(pf + "vICMSRet", objtransp.belRetTransp.Vicmsret.ToString("#0.00").Replace(',', '.')), new XElement(pf + "CFOP", objtransp.belRetTransp.Cfop.ToString()), new XElement(pf + "cMunFG", objtransp.belRetTransp.Cmunfg.ToString()))) : null), (objtransp.belVeicTransp != null ? (new XElement(pf + "veicTransp", (objtransp.belVeicTransp.Placa != null ? new XElement(pf + "placa", objtransp.belVeicTransp.Placa.ToString()) : null), (objtransp.belVeicTransp.Uf != null ? new XElement(pf + "UF", objtransp.belVeicTransp.Uf.ToString()) : null), (objtransp.belVeicTransp.Rntc != null ? new XElement(pf + "RNTC", objtransp.belVeicTransp.Rntc.ToString()) : null))) : null), (objtransp.belReboque != null ? new XElement(pf + "reboque", (objtransp.belReboque.Placa != null ? new XElement(pf + "placa", objtransp.belReboque.Placa.ToString()) : null), (objtransp.belReboque.Uf != null ? new XElement(pf + "UF", objtransp.belReboque.Uf.ToString()) : null), (objtransp.belReboque.Rntc != null ? new XElement(pf + "RNTC", objtransp.belReboque.Rntc.ToString()) : null)) : null), (objtransp.belVol != null ? new XElement(pf + "vol", new XElement(pf + "qVol", objtransp.belVol.Qvol.ToString("#")), new XElement(pf + "esp", objtransp.belVol.Esp.ToString()), new XElement(pf + "marca", objtransp.belVol.Marca.ToString()), (objtransp.belVol.Nvol != null ? new XElement(pf + "nVol", objtransp.belVol.Nvol.ToString()) : null),//Danner - o.s. 24385 - 26/04/2010 new XElement(pf + "pesoL", objtransp.belVol.PesoL.ToString("#0.000").Replace(",", ".")), new XElement(pf + "pesoB", objtransp.belVol.PesoB.ToString("#0.000").Replace(",", "."))) : null), (objtransp.belLacres != null ? new XElement(pf + "lacres", new XElement(pf + "nLacre", "")) : null))); #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Transporte - " + x.Message); } //Fim - Frete //Duplicata XContainer concobr; belCobr objcob; try { objcob = i[7] as belCobr; belGerarXML BuscaConexao = new belGerarXML(); #region XML_Cobrança concobr = (new XElement(pf + "cobr", new XElement(pf + "fat", new XElement(pf + "nFat", objcob.belFat.Nfat.ToString()), (objcob.belFat.Vorig != 0 ? new XElement(pf + "vOrig", objcob.belFat.Vorig.ToString("#0.00").Replace(",", ".")) : null), (objcob.belFat.Vdesc != null && objcob.belFat.Vdesc != 0 ? new XElement(pf + "vDesc", objcob.belFat.Vdesc.ToString("#0.00").Replace(",", ".")) : null), (objcob.belFat.Vliq != 0 ? new XElement(pf + "vLiq", objcob.belFat.Vliq.ToString("#0.00").Replace(",", ".")) : null)), (objcob.belFat.belDup != null ? from dup in objcob.belFat.belDup select new XElement(pf + "dup", new XElement(pf + "nDup", dup.Ndup.ToString()), new XElement(pf + "dVenc", dup.Dvenc.ToString("yyyy-MM-dd")), (BuscaConexao.nm_Cliente != "LORENZON" ? new XElement(pf + "vDup", dup.Vdup.ToString("#0.00").Replace(",", ".")) : null)) : null))); #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Region XML_Cobrança - " + x.Message); } //Fim - Duplicata //Obs XContainer conobs; belInfAdic objobs; try { objobs = i[8] as belInfAdic; #region XML_Obs conobs = new XElement(pf + "infAdic", (objobs.Infcpl != null ? new XElement(pf + "infCpl", objobs.Infcpl.ToString()) : null)); #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML,Regiao XML_Obs - " + x.Message); } //Fim - Obs //Uniao dos Containers try { concabec.Add(coninfnfe); coninfnfe.Add(conide); conide.AddAfterSelf(conemit); conemit.AddAfterSelf(condest); condest.AddAfterSelf(contotal); contotal.AddAfterSelf(contransp); if (concobr != null) { contransp.AddAfterSelf(concobr); if (objobs.Infcpl != null) concobr.AddAfterSelf(conobs); } else { if (objobs.Infcpl != null) contransp.AddAfterSelf(conobs); } foreach (XElement x in lcondet) { contotal.AddBeforeSelf(x); } } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro na montagem do XML, União dos Containers - " + x.Message); } try { AssinaNFeXml Assinatura = new AssinaNFeXml(); string nfe = Assinatura.ConfigurarArquivo(concabec.ToString(), "infNFe", cert); nfes.Add(nfe); XElement xnfe = XElement.Parse(nfe); XDocument xdocsalvanfesemlot = new XDocument(xnfe); DirectoryInfo dPastaData = new DirectoryInfo(glob.LeRegConfig("PastaXmlEnvio").ToString() + "\\" + sNFe.Substring(5, 4)); if (!dPastaData.Exists) { dPastaData.Create(); } if (sFormaEmiNFe.Equals("2")) { xdocsalvanfesemlot.Save(glob.LeRegConfig("PastaContingencia").ToString() + "\\" + sNFe.Replace("NFe", "") + "-nfe.xml"); } else { xdocsalvanfesemlot.Save(glob.LeRegConfig("PastaXmlEnvio").ToString() + "\\" + sNFe.Substring(5, 4) + "\\" + sNFe.Replace("NFe", "") + "-nfe.xml"); // OS_25024 } //StreamWriter swnfe = new StreamWriter(glob.LeRegWin("PastaXmlEnvio").ToString() + "\\" + sNFe.Replace("NFe", "") + "-nfe.xml"); //swnfe.Write(nfe); //swnfe.Close(); } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro ao assinar a nfe de sequencia " + sNota + x.Message); } iCount++; } //Concatenando as NFes. string sXmlComp = ""; //Junta todos os XML's em texto foreach (var i in nfes) { sXmlComp = sXmlComp + i; } //Estou inserindo o enviNFe pois se eu transformar o arquivo xml assinado em xml e depois em testo usando um toString, //a assinatura se torna invalida. Então depois de assinado do trabalho em forma de testo como xml ateh envia-lo pra fazenda. sXmlfull = "<?xml version=\"1.0\" encoding=\"utf-8\"?><enviNFe xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao=\"2.00\"><idLote>" + sNomeArq.Substring(7, 15) + "</idLote>" + sXmlComp + "</enviNFe>"; //Grava StreamWriter sw = new StreamWriter(sPath); sw.Write(sXmlfull); sw.Close(); #region Valida_Xml Globais getschema = new Globais(); //string sXml = File.OpenText(sPath).ReadToEnd(); XmlSchemaCollection myschema = new XmlSchemaCollection(); XmlValidatingReader reader; //Danner - o.s. 23732 - 06/11/2009 try { XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None); reader = new XmlValidatingReader(sXmlfull, XmlNodeType.Element, context); myschema.Add("http://www.portalfiscal.inf.br/nfe", getschema.LeRegConfig("PastaSchema") + "\\enviNFe_v2.00.xsd"); reader.ValidationType = ValidationType.Schema; reader.Schemas.Add(myschema); while (reader.Read()) { } } catch (XmlException x) { File.Delete(sPath); throw new Exception(x.Message); } catch (XmlSchemaException x) { File.Delete(sPath); throw new Exception(x.Message); } //Fim - Danner - o.s. 23732 - 06/11/2009 #endregion } catch (Exception ex) { Conn.Close(); throw ex; } finally { Conn.Close(); } }
internal XdrValidator(XmlValidatingReaderImpl reader, XmlSchemaCollection schemaCollection, IValidationEventHandling?eventHandling) : base(reader, schemaCollection, eventHandling) { Init(); }