public static System.Xml.XmlDocument SetInfopathForm( System.Xml.XmlDocument part, string InfopathFormUrl) { // Delete existing processing instructions. foreach (System.Xml.XmlNode pi in part.SelectNodes( "processing-instruction()")) { pi.ParentNode.RemoveChild(pi); } // Add an xml declaration System.Xml.XmlDeclaration decl = part.CreateXmlDeclaration("1.0", null, null); part.InsertBefore(decl, part.DocumentElement); // Create the mso-application procesing instruction. System.Xml.XmlProcessingInstruction progid = part.CreateProcessingInstruction( "mso-application", "progid='InfoPath.Document'"); part.InsertBefore(progid, part.DocumentElement); // Create the mso-infoPathSolution processing instruction System.Xml.XmlProcessingInstruction form = part.CreateProcessingInstruction( "mso-infoPathSolution", "PIVersion='1.0.0.0' href='" + InfopathFormUrl + "'"); part.InsertBefore(form, part.DocumentElement); return(part); }
/// <summary> /// Convertit un XmlNode en Linq To Xml /// </summary> /// <param name="oXmlNode"></param> /// <returns></returns> private string GetLinqToXml(System.Xml.XmlNode oXmlNode) { string result = string.Empty; // string LinqToXmlGenerated = string.Empty; if (!Options.IncludeLinqCompletePathNamespace) { LinqNamespace = string.Empty; } else { LinqNamespace = "System.Xml.Linq."; } currentNamespacePrefix = string.Empty; switch (oXmlNode.NodeType) { case System.Xml.XmlNodeType.Document: System.Xml.XmlDeclaration oXmlDeclaration = (System.Xml.XmlDeclaration)oXmlNode.FirstChild; result += LinqNamespace + "XDocument oXDocument = new " + LinqNamespace + "XDocument(new " + LinqNamespace + "XDeclaration(\"" + oXmlDeclaration.Version + "\",\"" + oXmlDeclaration.Encoding + "\",\"" + oXmlDeclaration.Standalone + "\"));\r"; break; case System.Xml.XmlNodeType.ProcessingInstruction: System.Xml.XmlProcessingInstruction oXmlProcessingInstruction = (System.Xml.XmlProcessingInstruction)oXmlNode; result += LinqNamespace + "XProcessingInstruction oXProcessingInstruction = new " + LinqNamespace + "XProcessingInstruction(\"" + oXmlProcessingInstruction.Name + "\", \"" + oXmlProcessingInstruction.Value + "\");\r"; break; case System.Xml.XmlNodeType.Comment: result += LinqNamespace + "XComment oXComment = new " + LinqNamespace + "XComment(\"" + oXmlNode.Value + "\");\r"; break; case System.Xml.XmlNodeType.Element: int nCount = 1; foreach (string Key in Namespaces.Keys) { result += LinqNamespace + "XNamespace " + Namespaces[Key] + " = \"" + Key + "\";" + Environment.NewLine; nCount += 1; } result += LinqNamespace + "XElement oXElement = \r"; result += BuildElement(oXmlNode, "\t\t\t"); result += "\r\t\t\t);\r"; break; case System.Xml.XmlNodeType.Attribute: result += LinqNamespace + "XAttribute oXAttribute = new " + LinqNamespace + "XAttribute(\"" + oXmlNode.Name + "\",\"" + oXmlNode.Value + "\");\r"; break; case System.Xml.XmlNodeType.Text: result += LinqNamespace + "XText oXText = new " + LinqNamespace + "XText(\"" + oXmlNode.Value + "\");\r"; break; } return(result); }
Stream(System.Xml.XmlLinkedNode lnkNode) { m_dataObjs.Add(new Snoop.Data.ClassSeparator(typeof(System.Xml.XmlLinkedNode))); // No data to show at this level, but we want to explicitly // show that there is an intermediate class. System.Xml.XmlElement elem = lnkNode as System.Xml.XmlElement; if (elem != null) { Stream(elem); return; } System.Xml.XmlCharacterData charData = lnkNode as System.Xml.XmlCharacterData; if (charData != null) { Stream(charData); return; } System.Xml.XmlDeclaration decl = lnkNode as System.Xml.XmlDeclaration; if (decl != null) { Stream(decl); return; } System.Xml.XmlDocumentType dType = lnkNode as System.Xml.XmlDocumentType; if (dType != null) { Stream(dType); return; } System.Xml.XmlEntityReference entRef = lnkNode as System.Xml.XmlEntityReference; if (entRef != null) { Stream(entRef); return; } System.Xml.XmlProcessingInstruction pi = lnkNode as System.Xml.XmlProcessingInstruction; if (pi != null) { Stream(pi); return; } }
public static bool _CreateProcessingInstruction_System_Xml_XmlDocument_System_String_System_String( ) { //Parameters System.String target = null; System.String data = null; //ReturnType/Value System.Xml.XmlProcessingInstruction returnVal_Real = null; System.Xml.XmlProcessingInstruction returnVal_Intercepted = null; //Exception Exception exception_Real = null; Exception exception_Intercepted = null; InterceptionMaintenance.disableInterception( ); try { returnValue_Real = System.Xml.XmlDocument.CreateProcessingInstruction(target, data); } catch (Exception e) { exception_Real = e; } InterceptionMaintenance.enableInterception( ); try { returnValue_Intercepted = System.Xml.XmlDocument.CreateProcessingInstruction(target, data); } catch (Exception e) { exception_Intercepted = e; } Return((exception_Real.Messsage == exception_Intercepted.Message) && (returnValue_Real == returnValue_Intercepted)); }
Stream(System.Xml.XmlProcessingInstruction pi) { m_dataObjs.Add(new Snoop.Data.ClassSeparator(typeof(System.Xml.XmlProcessingInstruction))); m_dataObjs.Add(new Snoop.Data.String("Target", pi.Target)); }
/// <summary> /// Modifica l'header del file XML della fatturazione elettronica con /// l'intestazione per il xlst in modo da essere visualizzato in modo umano /// Faillace 23/6/2014 /// </summary> /// <param name="xmlByteArray">xml in ingresso</param> /// <returns>xml in uscita, se non è di tipo fatturazione , restituisce null</returns> private byte[] fatturazioneElettronicaInsertXlst(byte[] xmlByteArray) { System.Xml.XmlDocument xd = new System.Xml.XmlDocument(); System.IO.TextReader tr = new System.IO.StreamReader(new System.IO.MemoryStream(xmlByteArray)); string fattura = tr.ReadToEnd(); fattura = fattura.Replace("<?xml version=\"1.1", "<?xml version=\"1.0"); //FIX per l'xml 1.1 (che non viene processato da dotnet) try { xd.LoadXml(fattura); //controllo se il namespace è tipo fattura elettronica if (xd.DocumentElement.NamespaceURI.ToLower().Equals("http://www.fatturapa.gov.it/sdi/fatturapa/v1.0") || xd.DocumentElement.NamespaceURI.ToLower().Equals("http://www.fatturapa.gov.it/sdi/fatturapa/v1.1")) { System.Xml.XmlNamespaceManager mgr = new System.Xml.XmlNamespaceManager(xd.NameTable); //se lo è aggiungo il namespace e il prefix mgr.AddNamespace(xd.DocumentElement.Prefix, xd.DocumentElement.NamespaceURI); //faccio una ricerca xpat per trovare il nodo FatturaElettronica // Old Code //System.Xml.XmlNode xn = xd.SelectSingleNode("//p:FatturaElettronica", mgr); // New Code System.Xml.XmlNode xn = null; if (!string.IsNullOrEmpty(xd.DocumentElement.Prefix)) { xn = xd.SelectSingleNode("//" + xd.DocumentElement.Prefix + ":FatturaElettronica", mgr); } else { //xn = xd.SelectSingleNode("FatturaElettronica"); if (xd.DocumentElement != null && !string.IsNullOrEmpty(xd.DocumentElement.Name) && xd.DocumentElement.Name.Equals("FatturaElettronica")) { xn = xd.DocumentElement; } else { xn = xd.SelectSingleNode("FatturaElettronica"); } } if (xn != null) { string nsUri = xd.DocumentElement.NamespaceURI.ToLower(); //Se è una fattura elettronica creo l'intestazione xlst con in path il file di trasfomazione che sta nell'xml di DPA System.Xml.XmlProcessingInstruction dpaProcessingInformation = xd.CreateProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"../xml/fatturapa_v1.0.xsl\""); if (nsUri.EndsWith("v1.1")) { dpaProcessingInformation = xd.CreateProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"../xml/fatturapa_v1.1.xsl\""); } //Ricerco il un eventuale xlst preessitente nel file xml System.Xml.XmlProcessingInstruction foundProcessingInformation = xd.SelectSingleNode("//processing-instruction(\"xml-stylesheet\")") as System.Xml.XmlProcessingInstruction; if (foundProcessingInformation != null) { // se lo trova lo rimpazza con quello geenrato sopra xd.ReplaceChild(dpaProcessingInformation, foundProcessingInformation); } else { //inserisce l'xlst in cima al documento prima del primo tag xd.InsertBefore(dpaProcessingInformation, xn); } //preparo un memorystream per l'output System.IO.MemoryStream msOut = new System.IO.MemoryStream(); //salvo il risultato sul memorystream xd.Save(msOut); //esco con il risultato return(msOut.ToArray()); } } } // il caricamento dell'xml ha dato errore (xml non formattato, tag non chiusi etc etc etc) catch { } //l'eleaborazione è avvenuta in modo corretto, o non è una fattura elettronica //oppure non è un xml oppure si è verificato un errore return(null); }
/// <summary> /// Modifica l'header del file XML della fatturazione elettronica con /// l'intestazione per il xlst in modo da essere visualizzato in modo umano /// Faillace 23/6/2014 /// </summary> /// <param name="xmlByteArray">xml in ingresso</param> /// <returns>xml in uscita, se non è di tipo fatturazione , restituisce null</returns> private byte[] fatturazioneElettronicaInsertXlst(byte[] xmlByteArray) { System.Xml.XmlDocument xd = new System.Xml.XmlDocument(); //Predisposizione FIX xml 1.1 se escono anomalie decommenta il codice sotto e sostituisci la xd.Load con la xd.LoadXml nel try. System.IO.TextReader tr = new System.IO.StreamReader(new System.IO.MemoryStream(xmlByteArray)); string fattura = tr.ReadToEnd(); fattura = fattura.Replace("<?xml version=\"1.1", "<?xml version=\"1.0"); //FIX per l'xml 1.1 (che non viene processato da dotnet) bool isFattura = false; try { xd.LoadXml(fattura); //xd.Load(new System.IO.MemoryStream(xmlByteArray)); //controllo se il namespace è tipo fattura elettronica if (xd.DocumentElement.NamespaceURI.ToLower().Equals("http://www.fatturapa.gov.it/sdi/fatturapa/v1.0") || xd.DocumentElement.NamespaceURI.ToLower().Equals("http://www.fatturapa.gov.it/sdi/fatturapa/v1.1") || xd.DocumentElement.NamespaceURI.ToLower().Equals("http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2")) { System.Xml.XmlNamespaceManager mgr = new System.Xml.XmlNamespaceManager(xd.NameTable); //se lo è aggiungo il namespace e il prefix mgr.AddNamespace(xd.DocumentElement.Prefix, xd.DocumentElement.NamespaceURI); //faccio una ricerca xpat per trovare il nodo FatturaElettronica // Old Code //System.Xml.XmlNode xn = xd.SelectSingleNode("//p:FatturaElettronica", mgr); // New Code System.Xml.XmlNode xn = null; if (!string.IsNullOrEmpty(xd.DocumentElement.Prefix)) { xn = xd.SelectSingleNode("//" + xd.DocumentElement.Prefix + ":FatturaElettronica", mgr); } else { //xn = xd.SelectSingleNode("FatturaElettronica"); if (xd.DocumentElement != null && !string.IsNullOrEmpty(xd.DocumentElement.Name) && xd.DocumentElement.Name.Equals("FatturaElettronica")) { xn = xd.DocumentElement; } else { xn = xd.SelectSingleNode("FatturaElettronica"); } } if (xn != null) { string nsUri = xd.DocumentElement.NamespaceURI.ToLower(); //Se è una fattura elettronica creo l'intestazione xlst con in path il file di trasfomazione che sta nell'xml di DPA System.Xml.XmlProcessingInstruction dpaProcessingInformation = xd.CreateProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"../xml/fatturapa_v1.0.xsl\""); if (nsUri.EndsWith("v1.1")) { dpaProcessingInformation = xd.CreateProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"../xml/fatturapa_v1.1.xsl\""); } else if (nsUri.EndsWith("v1.2")) { dpaProcessingInformation = xd.CreateProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"../xml/fatturapa_v1.2.xsl\""); } //Ricerco il un eventuale xlst preessitente nel file xml System.Xml.XmlProcessingInstruction foundProcessingInformation = xd.SelectSingleNode("//processing-instruction(\"xml-stylesheet\")") as System.Xml.XmlProcessingInstruction; if (foundProcessingInformation != null) { // se lo trova lo rimpazza con quello geenrato sopra xd.ReplaceChild(dpaProcessingInformation, foundProcessingInformation); } else { //inserisce l'xlst in cima al documento prima del primo tag xd.InsertBefore(dpaProcessingInformation, xn); } //preparo un memorystream per l'output System.IO.MemoryStream msOut = new System.IO.MemoryStream(); //salvo il risultato sul memorystream xd.Save(msOut); isFattura = true; //esco con il risultato return(msOut.ToArray()); } } if (!isFattura && (xd.DocumentElement.NamespaceURI.ToLower().Equals("http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fattura/messaggi/v1.0") || xd.DocumentElement.NamespaceURI.ToLower().Equals("http://www.fatturapa.gov.it/sdi/fatturapa/v1.0") || xd.DocumentElement.NamespaceURI.ToLower().Equals("http://www.fatturapa.gov.it/sdi/messaggi/v1.0"))) { // Ricevute SDI System.Xml.XmlNamespaceManager mgr = new System.Xml.XmlNamespaceManager(xd.NameTable); if (xd.DocumentElement.NamespaceURI.ToLower().Equals("http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fattura/messaggi/v1.0")) { mgr.AddNamespace("ns3", "http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fattura/messaggi/v1.0"); } else if (xd.DocumentElement.NamespaceURI.ToLower().Equals("http://www.fatturapa.gov.it/sdi/fatturapa/v1.0")) { mgr.AddNamespace("ns3", "http://www.fatturapa.gov.it/sdi/fatturapa/v1.0"); } else if (xd.DocumentElement.NamespaceURI.ToLower().Equals("http://www.fatturapa.gov.it/sdi/messaggi/v1.0")) { mgr.AddNamespace("ns3", "http://www.fatturapa.gov.it/sdi/messaggi/v1.0"); } else { return(null); } string urlXSL = string.Empty; if (xd.SelectSingleNode("//ns3:RicevutaConsegna", mgr) != null) { urlXSL = "../xml/RC_v1.1.xsl"; } else if (xd.SelectSingleNode("//ns3:NotificaMancataConsegna", mgr) != null || xd.SelectSingleNode("//ns3:RicevutaImpossibilitaRecapito", mgr) != null) { urlXSL = "../xml/MC_v1.1.xsl"; } else if (xd.SelectSingleNode("//ns3:NotificaScarto", mgr) != null || xd.SelectSingleNode("//ns3:RicevutaScarto", mgr) != null) { urlXSL = "../xml/NS_v1.1.xsl"; } else if (xd.SelectSingleNode("//ns3:NotificaEsito", mgr) != null) { urlXSL = "../xml/EC_v1.0.xsl"; } else if (xd.SelectSingleNode("//ns3:NotificaDecorrenzaTermini", mgr) != null) { urlXSL = "../xml/DT_v1.0.xsl"; } else if (xd.SelectSingleNode("//types:ScartoEsitoCommittente", mgr) != null) { urlXSL = "../xml/SE_v1.0.xsl"; } string decl = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; string decl8 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; string pi = "<?xml-stylesheet type=\"text/xsl\" href=\"" + urlXSL + "\"?>"; string previewXml = fattura.Replace(decl, decl + "\n" + pi); previewXml = previewXml.Replace(decl8, decl8 + "\n" + pi); xd.LoadXml(previewXml); Byte[] bytes = System.Text.Encoding.UTF8.GetBytes(xd.OuterXml); return(bytes); } } catch (Exception) { } return(null); }
public XmlProcessingInstruction(XmlDocument owner, SystemProcessingInstruction backingProcessingInstruction) { _owner = owner; _backingProcessingInstruction = backingProcessingInstruction; }