private XmlDocument CreateTestDoc() { XmlDocument doc = new XmlDocument(); XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "utf-8", null); doc.InsertBefore(xmlDeclaration, doc.DocumentElement); // it is necessary to have this root node without attributes, to comply with the xml documents generated by TYML2XML XmlElement rootNode = doc.CreateElement(TYml2Xml.ROOTNODEINTERNAL); doc.AppendChild(rootNode); XmlElement childNode = doc.CreateElement(TYml2Xml.XMLELEMENT); childNode.SetAttribute("name", "testname"); childNode.SetAttribute("active", true.ToString()); rootNode.AppendChild(childNode); XmlElement anotherChildNode = doc.CreateElement(TYml2Xml.XMLELEMENT); anotherChildNode.SetAttribute("name", "testname2"); anotherChildNode.SetAttribute("active", true.ToString()); rootNode.AppendChild(anotherChildNode); XmlElement grandChildNode = doc.CreateElement(TYml2Xml.XMLELEMENT); grandChildNode.SetAttribute("name", "grandchild1"); grandChildNode.SetAttribute("active", true.ToString()); childNode.AppendChild(grandChildNode); XmlElement grandChild2Node = doc.CreateElement(TYml2Xml.XMLELEMENT); grandChild2Node.SetAttribute("name", "grandchild2"); grandChild2Node.SetAttribute("active", false.ToString()); childNode.AppendChild(grandChild2Node); return doc; }
void Save() { var doc = new System.Xml.XmlDocument(); var xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null); var root = doc.DocumentElement; doc.InsertBefore(xmlDeclaration, root); var records = doc.CreateElement("records"); doc.AppendChild(records); var tables = doc.CreateElement(string.Empty, "tables", string.Empty); var singleRecords = doc.CreateElement(string.Empty, "srec", string.Empty); var teamRecords = doc.CreateElement(string.Empty, "trec", string.Empty); records.AppendChild(singleRecords); records.AppendChild(teamRecords); records.AppendChild(tables); // single records: foreach (var s in this.mSingleStorage) { var r = doc.CreateElement(string.Empty, "record", string.Empty); var dsvId = doc.CreateAttribute("id"); dsvId.Value = s.SwimmerId; r.Attributes.Append(dsvId); } }
public void GenerateAllLocationsReport(IEnumerable<LocationReport> locationReports) { var report = new XmlDocument(); var xmlDeclaration = report.CreateXmlDeclaration("1.0", "UTF-8", null); var root = report.CreateElement("sales"); report.AppendChild(root); report.InsertBefore(xmlDeclaration, root); foreach (var locationReport in locationReports) { var sale = report.CreateElement("location"); sale.SetAttribute("name", locationReport.LocationName); root.AppendChild(sale); foreach (var entry in locationReport.Entries) { var summary = report.CreateElement("summary"); summary.SetAttribute("date", entry.Date.ToString("dd-MMM-yyyy", CultureInfo.InvariantCulture)); summary.SetAttribute("total-sum", entry.TotalSum.ToString(CultureInfo.InvariantCulture)); sale.AppendChild(summary); } } if (!Directory.Exists(XmlSettings.Default.ReportDestinationFolderLocation)) { Directory.CreateDirectory(XmlSettings.Default.ReportDestinationFolderLocation); } report.Save( XmlSettings.Default.ReportDestinationFolderLocation + XmlSettings.Default.ReportDestionationFileName); }
////////////////////////////////////////////////////////////////////////// public bool SaveToXmlFile(string Filename) { try { XmlDocument Doc = new XmlDocument(); // header XmlDeclaration Decl = Doc.CreateXmlDeclaration("1.0", "utf-8", null); Assembly A = Assembly.GetExecutingAssembly(); XmlComment Comment1 = Doc.CreateComment("Generated by: " + A.GetName()); XmlComment Comment2 = Doc.CreateComment("Generated on: " + DateTime.Now.ToString()); // root XmlNode RootNode = SaveToXmlNode(Doc); Doc.InsertBefore(Decl, Doc.DocumentElement); Doc.AppendChild(Comment1); Doc.AppendChild(Comment2); Doc.AppendChild(RootNode); // save to file XmlTextWriter Writer = new XmlTextWriter(Filename, null); Writer.Formatting = Formatting.Indented; Doc.Save(Writer); Writer.Close(); return true; } catch { return false; } }
static void Main() { XmlDocument doc = new XmlDocument(); XmlDocument outputDoc = new XmlDocument(); doc.Load("../../../catalog.xml"); Console.WriteLine("Loaded XML document:"); XmlNode Root = doc.DocumentElement; XmlDeclaration xmlDeclaration = outputDoc.CreateXmlDeclaration("1.0", "UTF-8", null); XmlElement root = outputDoc.DocumentElement; outputDoc.InsertBefore(xmlDeclaration, root); XmlElement element1 = outputDoc.CreateElement(string.Empty, "albums", string.Empty); outputDoc.AppendChild(element1); foreach (XmlNode album in Root.ChildNodes) { if (int.Parse(album.ChildNodes[3].Attributes["value"].Value) > 20) { XmlNode oNode = outputDoc.ImportNode(album, true); outputDoc.DocumentElement.AppendChild(oNode); } } outputDoc.Save("../../../document.xml"); }
/// <summary> /// Generates an XML containing WMTS capabilities. /// </summary> /// <param name="map">A MapAround.Mapping.Map instance</param> /// <param name="serviceDescription"></param> /// <returns>A System.Xml.XmlDocument instance containing WMTS capabilities in compliance to the WMS standard</returns> public static XmlDocument GetCapabilities(Map map, WmtsServiceDescription serviceDescription) { XmlDocument capabilities = new XmlDocument(); capabilities.InsertBefore(capabilities.CreateXmlDeclaration("1.0", "UTF-8", string.Empty), capabilities.DocumentElement); XmlNode rootNode = capabilities.CreateNode(XmlNodeType.Element, "WMTS_Capabilities", wmtsNamespaceURI); rootNode.Attributes.Append(createAttribute("version", "1.0.0", capabilities)); XmlAttribute attr = capabilities.CreateAttribute("xmlns", "xsi", "http://www.w3.org/2000/xmlns/"); attr.InnerText = "http://www.w3.org/2001/XMLSchema-instance"; rootNode.Attributes.Append(attr); rootNode.Attributes.Append(createAttribute("xmlns:xlink", xlinkNamespaceURI, capabilities)); XmlAttribute attr2 = capabilities.CreateAttribute("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance"); rootNode.AppendChild(GenerateServiceNode(ref serviceDescription, capabilities)); rootNode.AppendChild(GenerateCapabilityNode(map, serviceDescription, capabilities)); capabilities.AppendChild(rootNode); return capabilities; }
public void GenerateSalesReport(string fileName = DefaultSaleReportFileName) { XmlDocument report = new XmlDocument(); XmlDeclaration xmlDeclaration = report.CreateXmlDeclaration("1.0", "UTF-8", null); XmlElement root = report.CreateElement("sales"); report.AppendChild(root); report.InsertBefore(xmlDeclaration, root); using (var db = new CarPartsDbContext()) { var groupedSales = db.Sales.GroupBy(s => s.Vendor) .ToList(); foreach (var group in groupedSales) { XmlElement sale = report.CreateElement("sale"); sale.SetAttribute("vendor", group.Key.Name); root.AppendChild(sale); foreach (var s in group) { XmlElement summary = report.CreateElement("summary"); summary.SetAttribute("date", s.Date.ToString("dd-MMM-yyyy", CultureInfo.InvariantCulture)); summary.SetAttribute("total-sum", (s.UnitPrice * s.Quantity).ToString()); sale.AppendChild(summary); } } } if (!Directory.Exists(this.reportsDestinationPath)) { Directory.CreateDirectory(this.reportsDestinationPath); } report.Save(this.reportsDestinationPath + fileName); }
/// <summary> /// /// </summary> /// <param name="items"></param> /// <param name="command"></param> /// <param name="schedule"></param> public void SetXmLsitemap(Item[] items, CommandItem command, ScheduleItem schedule) { if (ConfigurationHelper.IsAuthoringServer()) { try { XmlDocument xmlDoc = new XmlDocument(); XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); XmlElement rootNode = xmlDoc.CreateElement("urlset"); rootNode.SetAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9"); xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement); xmlDoc.AppendChild(rootNode); //we will take only approved items / pages string databaseName = "web"; string startItemPath = ConfigurationHelper.GetSitecoreSetting("rootPath"); Database database = Factory.GetDatabase(databaseName); UrlOptions urlOptions = UrlOptions.DefaultOptions; urlOptions.AlwaysIncludeServerUrl = false; Item item = database.GetItem(startItemPath); AddUrlEntry(item, xmlDoc, rootNode, urlOptions); xmlDoc.Save(System.Web.Hosting.HostingEnvironment.MapPath("/sitemap.xml")); } catch (Exception ex) { Log.Error("Error at sitemap xml handler.", ex, this); } } }
/// <summary> /// Saves the current collection of Host Instances to disk /// </summary> /// <param name="xmlDocName">Filename (verbatim) to save data to - User AppData Path is prepended /// if the path does not start with either ?: or \\</param> public virtual void ToXml(String xmlDocName) { System.Xml.XmlDocument xmlData = new System.Xml.XmlDocument(); // Create the XML Declaration (well formed) XmlDeclaration xmlDeclaration = xmlData.CreateXmlDeclaration("1.0", "utf-8", null); xmlData.InsertBefore(xmlDeclaration, xmlData.DocumentElement); // Create the root element System.Xml.XmlElement xmlRoot = xmlData.CreateElement("Hosts"); // Loop through the collection and serialize the lot foreach (KeyValuePair <String, Base> de in this) { Base fi = (Base)de.Value; XmlDocument xmlDoc = fi.ToXml(); foreach (XmlNode xn in xmlDoc.ChildNodes) { xmlRoot.AppendChild(xmlData.ImportNode(xn, true)); } } xmlData.AppendChild(xmlRoot); // Save the XML stream to the file if ((xmlDocName.Substring(1, 1) == ":") || (xmlDocName.StartsWith("\\\\"))) { xmlData.Save(xmlDocName); } else { xmlData.Save(Preferences.PreferenceSet.Instance.AppDataPath + "\\" + xmlDocName); } }
public static XmlDocument CreateXmlDocument() { XmlDocument doc = new XmlDocument(); XmlDeclaration decl = doc.CreateXmlDeclaration("1.0", "utf-8", ""); doc.InsertBefore(decl, doc.DocumentElement); return doc; }
public static void GerarConfiguracao(string Servidor, string BD) { // Pasta aonde está o arquivo + nome do arquivo a ser gerado. string arquivo = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + Path.DirectorySeparatorChar + "conexao.xml"; // Criação do Xml com os dados XmlDocument xml = new XmlDocument(); XmlDeclaration declaracaoXml = xml.CreateXmlDeclaration("1.0", "utf-8", null); XmlElement noRaiz = xml.CreateElement("Configuracao"); xml.InsertBefore(declaracaoXml, xml.DocumentElement); xml.AppendChild(noRaiz); XmlElement noPai = xml.CreateElement("Servidor"); xml.DocumentElement.PrependChild(noPai); XmlElement endereco= xml.CreateElement("Endereco"); XmlElement database = xml.CreateElement("Database"); // Inserir Texto XmlText enderecoText = xml.CreateTextNode(Servidor); XmlText databaseText= xml.CreateTextNode(BD); // append the nodes to the parentNode without the value noPai.AppendChild(endereco); noPai.AppendChild(database); // save the value of the fields into the nodes endereco.AppendChild(enderecoText); database.AppendChild(databaseText); // Save to the XML file xml.Save(arquivo.Substring(6,arquivo.Length - 6)); }
/// <summary> /// Generates a capabilities file from a map object for use in WMS services /// </summary> /// <remarks>The capabilities document uses the v1.3.0 OpenGIS WMS specification</remarks> /// <param name="map">The map to create capabilities for</param> /// <param name="description">Additional description of WMS</param> /// <param name="request">An abstraction of the <see cref="HttpContext"/> request</param> /// <returns>Returns XmlDocument describing capabilities</returns> public static XmlDocument GetCapabilities(Map map, WmsServiceDescription description, IContextRequest request) { XmlDocument capabilities = new XmlDocument(); // Insert XML tag capabilities.InsertBefore(capabilities.CreateXmlDeclaration("1.0", "UTF-8", String.Empty), capabilities.DocumentElement); string format = String.Format("Capabilities generated by SharpMap v. {0}", Assembly.GetExecutingAssembly().GetName().Version); capabilities.AppendChild(capabilities.CreateComment(format)); // Create root node XmlNode rootNode = capabilities.CreateNode(XmlNodeType.Element, "WMS_Capabilities", WmsNamespaceUri); rootNode.Attributes.Append(CreateAttribute("version", "1.3.0", capabilities)); XmlAttribute attr = capabilities.CreateAttribute("xmlns", "xsi", "http://www.w3.org/2000/xmlns/"); attr.InnerText = "http://www.w3.org/2001/XMLSchema-instance"; rootNode.Attributes.Append(attr); rootNode.Attributes.Append(CreateAttribute("xmlns:xlink", XlinkNamespaceUri, capabilities)); XmlAttribute attr2 = capabilities.CreateAttribute("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance"); attr2.InnerText = "http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd"; rootNode.Attributes.Append(attr2); // Build Service node rootNode.AppendChild(GenerateServiceNode(ref description, capabilities)); // Build Capability node XmlNode capabilityNode = GenerateCapabilityNode(map, capabilities, description.PublicAccessURL, request); rootNode.AppendChild(capabilityNode); capabilities.AppendChild(rootNode); //TODO: Validate output against schema return capabilities; }
public XmlDocument Xml() { if (_manifestXml != null) return _manifestXml; _manifestXml = new XmlDocument {PreserveWhitespace = true}; var xmlDeclaration = _manifestXml.CreateXmlDeclaration("1.0", "UTF-8", null); _manifestXml.AppendChild(_manifestXml.CreateElement("manifest", NavneromUtility.DifiSdpSchema10)); _manifestXml.InsertBefore(xmlDeclaration, _manifestXml.DocumentElement); if (Forsendelse.Sendes(Postmetode.Digital)) { _manifestXml.DocumentElement.AppendChild(MottakerNode()); } _manifestXml.DocumentElement.AppendChild(AvsenderNode()); var hoveddokument = Forsendelse.Dokumentpakke.Hoveddokument; _manifestXml.DocumentElement.AppendChild(DokumentNode(hoveddokument, "hoveddokument", hoveddokument.Tittel)); foreach (var vedlegg in Forsendelse.Dokumentpakke.Vedlegg) { _manifestXml.DocumentElement.AppendChild(DokumentNode(vedlegg, "vedlegg", vedlegg.Tittel)); } return _manifestXml; }
public static string CreateNewLodgeXmlFile(string xmlFileName) { string success = "ono"; try { XmlDocument xdoc = new XmlDocument(); XmlDeclaration xmlDeclaration = xdoc.CreateXmlDeclaration("1.0", "utf-8", null); xdoc.InsertBefore(xmlDeclaration, xdoc.DocumentElement); var root = xdoc.CreateElement("Lodge"); xdoc.AppendChild(root); root.AppendChild(xdoc.CreateElement("Members")); root.AppendChild(xdoc.CreateElement("CalendarEvents")); root.AppendChild(xdoc.CreateElement("Committees")); root.AppendChild(xdoc.CreateElement("Officers")); root.AppendChild(xdoc.CreateElement("Minutes")); root.AppendChild(xdoc.CreateElement("Inventory")); root.AppendChild(xdoc.CreateElement("Cash")); root.AppendChild(xdoc.CreateElement("People")); root.AppendChild(xdoc.CreateElement("Refs")); //AddDefaulRefs(xdoc); xdoc.Save(xmlFileName); ResetDefaults(xmlFileName); success = "ok"; } catch (Exception ex) { success = ex.Message; } return success; }
public static int Main (string [] args) { if (args.Length == 0) return 1; AbiMode = false; AssemblyCollection acoll = new AssemblyCollection (); foreach (string arg in args) { if (arg == "--abi") AbiMode = true; else acoll.Add (arg); } XmlDocument doc = new XmlDocument (); acoll.Document = doc; acoll.DoOutput (); var writer = new WellFormedXmlWriter (new XmlTextWriter (Console.Out) { Formatting = Formatting.Indented }); XmlNode decl = doc.CreateXmlDeclaration ("1.0", "utf-8", null); doc.InsertBefore (decl, doc.DocumentElement); doc.WriteTo (writer); return 0; }
public System.Xml.XmlDocument CreatePackagesDotConfigFile(IEnumerable<Models.NugetPackageInfo> packages) { XmlDocument doc = new XmlDocument(); XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null); XmlElement root = doc.DocumentElement; doc.InsertBefore(xmlDeclaration, root); XmlElement packagesElement = doc.CreateElement(string.Empty, "packages", string.Empty); doc.AppendChild(packagesElement); foreach (NugetPackageInfo package in packages) { XmlElement packageElement = doc.CreateElement(string.Empty, "package", string.Empty); packagesElement.AppendChild(packageElement); XmlAttribute idAttribute = doc.CreateAttribute("id"); idAttribute.Value = package.Info.Name; packageElement.Attributes.Append(idAttribute); XmlAttribute versionAttribute = doc.CreateAttribute("version"); versionAttribute.Value = package.Info.VersionNumber.ToString(); packageElement.Attributes.Append(versionAttribute); XmlAttribute frameworkAttribute = doc.CreateAttribute("targetFramework"); frameworkAttribute.Value = "net45"; packageElement.Attributes.Append(frameworkAttribute); } return doc; }
public void Initiate() { try { string timelineFolder = Environment.CurrentDirectory + "/Timelines"; if (!Directory.Exists(timelineFolder)) { Directory.CreateDirectory(timelineFolder); } string fileName = DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss") + ".xml"; xmlDoc = new XmlDocument(); XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); //create root XmlElement rootNode = xmlDoc.CreateElement("TIMELINE"); xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement); xmlDoc.AppendChild(rootNode); string fullFilePath = timelineFolder + "/" + fileName; currentFileName = fullFilePath; if (!File.Exists(fullFilePath)) { FileStream fs = File.Create(fullFilePath); fs.Close(); } xmlDoc.Save(fullFilePath); } catch (Exception ex) { Utilities.UtilitiesLib.LogError(ex); } }
private void CreateBasicRssDoc(XmlDocument doc, string title, string description, string link) { XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "utf-8", null); doc.InsertBefore(declaration, doc.DocumentElement); XmlElement rssNode = doc.CreateElement("rss"); XmlAttribute rssAtt = doc.CreateAttribute("version"); rssAtt.Value = "2.0"; rssNode.Attributes.Append(rssAtt); XmlElement channelNode = doc.CreateElement("channel"); XmlElement titleNode = doc.CreateElement("title"); titleNode.InnerText = title; channelNode.AppendChild(titleNode); XmlElement desNode = doc.CreateElement("description"); desNode.InnerText = description; channelNode.AppendChild(desNode); XmlElement linkNode = doc.CreateElement("link"); linkNode.InnerText = link; channelNode.AppendChild(linkNode); rssNode.AppendChild(channelNode); doc.AppendChild(rssNode); }
private static void _processDocument(XmlNode document, StreamWriter sw) { XmlDocument docNode = new XmlDocument(); XmlDeclaration xmlDeclaration = docNode.CreateXmlDeclaration("1.0", "cp866", null); docNode.InsertBefore(xmlDeclaration, docNode.DocumentElement); XmlElement docRoot = (XmlElement)docNode.ImportNode(document, true); docNode.AppendChild(docRoot); Regex rgx = new Regex("<(\\w+)>"); String s = rgx.Replace(docNode.OuterXml, "<$1 xmlns=\"itek\">"); s = s.Replace("<Документ xmlns=\"itek\">", "<Документ>"); s = s.Replace("РаботыЧужие", "true"); eurocarService.Документ documentRequest = (eurocarService.Документ)_x.Deserialize(new System.IO.StringReader(s)); try { sw.WriteLine(DateTime.Now.ToString() + " Отправка документа " + documentRequest.Номер); _cl.PutDoc(documentRequest); } catch (ProtocolException e) { // Silently except it... } }
/// <summary> /// Converts entries in a XML document. /// </summary> /// <param name="entries">The entries.</param> /// <returns>The XML document that represents the entries.</returns> public string Convert(IEnumerable<string> entries) { var doc = new XmlDocument(); var xmlDeclaration = doc.CreateXmlDeclaration("1.0", "utf-8", null); var root = doc.DocumentElement; doc.InsertBefore(xmlDeclaration, root); var rootElement = doc.CreateElement("directory"); foreach (var entry in entries) { var element = doc.CreateElement("entry"); var textNode = doc.CreateTextNode(entry); element.AppendChild(textNode); rootElement.AppendChild(element); } doc.AppendChild(rootElement); using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture)) using (var xmlTextWriter = XmlWriter.Create(stringWriter)) { doc.WriteTo(xmlTextWriter); xmlTextWriter.Flush(); return stringWriter.GetStringBuilder().ToString(); } }
public XmlDocument GetXml(String xslFile) { XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("licenses"); doc.AppendChild(root); if (!String.IsNullOrEmpty(xslFile)) { XmlNode pi = doc.CreateProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"" + xslFile + "\""); doc.InsertBefore(pi, root); } foreach (LicenseInfo license in _licenses.Values) { XmlElement licenseElement = doc.CreateElement("license"); licenseElement.SetAttribute("productName", license.Product); licenseElement.SetAttribute("productVersion", license.Version); if (!String.IsNullOrEmpty(license.ParentProduct)) { licenseElement.SetAttribute("parentProduct", license.ParentProduct); } if (!String.IsNullOrEmpty(license.LicenseFilename)) { licenseElement.SetAttribute("filename", license.LicenseFilename); } if (!String.IsNullOrEmpty(license.LicenseType)) { licenseElement.SetAttribute("licenseType", license.LicenseType); } if (!String.IsNullOrEmpty(license.Url)) { licenseElement.SetAttribute("url", license.Url); } root.AppendChild(licenseElement); } return doc; }
static void Main(string[] args) { var ctx = new GeographyEntities(); var countries = ctx.Countries.Where(m => m.Monasteries.Count() > 0).Select(c => new { country = c.CountryName, monastery = c.Monasteries.OrderBy(m => m.Name).Select(m => m.Name) }) .OrderBy(c => c.country); XmlDocument doc = new XmlDocument(); XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null); XmlElement root = doc.DocumentElement; doc.InsertBefore(xmlDeclaration, root); var body = doc.CreateElement("monasteries"); doc.AppendChild(body); foreach (var item in countries) { var country = doc.CreateElement("country"); country.SetAttribute("name", item.country); body.AppendChild(country); foreach (var monk in item.monastery) { var mon = doc.CreateElement("monastery"); mon.InnerText = monk; country.AppendChild(mon); } } doc.Save("monasteries.xml"); }
private XmlDocument CreateMessage(string data, object recipients) { var doc = new XmlDocument(); XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null); XmlElement root = doc.DocumentElement; doc.InsertBefore(xmlDeclaration, root); XmlElement e0 = doc.CreateElement(string.Empty, "Message", string.Empty); doc.AppendChild(e0); XmlElement e2 = doc.CreateElement(string.Empty, "Data", string.Empty); e2.AppendChild(doc.CreateTextNode(data)); e0.AppendChild(e2); XmlElement e3 = doc.CreateElement(string.Empty, "Recipients", string.Empty); e0.AppendChild(e3); foreach (string s in ObjectToStringArray(recipients)) { XmlElement e4 = doc.CreateElement(string.Empty, "Recipient", string.Empty); e4.AppendChild(doc.CreateTextNode(s)); e3.AppendChild(e4); } return doc; }
public void EcrireFichier(String NomFichier) { // Créer le document xml desvariables Trier(); XmlDocument monXMLDeVariables = new XmlDocument(); XmlDeclaration maDeclaration = monXMLDeVariables.CreateXmlDeclaration("1.0","UTF-8", null); XmlElement root = monXMLDeVariables.DocumentElement; monXMLDeVariables.InsertBefore(maDeclaration ,root); XmlElement monElementListe = monXMLDeVariables.CreateElement (String.Empty ,"ListeDeVariables" , String.Empty ); monXMLDeVariables.AppendChild(monElementListe); foreach (KeyValuePair<String, String> maPaire in Variables ) { XmlElement maVariable = monXMLDeVariables.CreateElement (String.Empty,"Variable",String.Empty); maVariable.SetAttribute("Cle", maPaire.Key); maVariable.SetAttribute("Valeur", maPaire.Value ); monElementListe.AppendChild(maVariable); } // sauver le document monXMLDeVariables.Save(NomFichier ); }
private static XmlDeclaration AppendDecleration(XmlDocument xmlDoc) { // Write down the XML declaration XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement); return xmlDeclaration; }
// This function generates the XML request body // for the FolderSync request. protected override void GenerateXMLPayload() { // If WBXML was explicitly set, use that if (WbxmlBytes != null) return; // Otherwise, use the properties to build the XML and then WBXML encode it XmlDocument folderSyncXML = new XmlDocument(); XmlDeclaration xmlDeclaration = folderSyncXML.CreateXmlDeclaration("1.0", "utf-8", null); folderSyncXML.InsertBefore(xmlDeclaration, null); XmlNode folderSyncNode = folderSyncXML.CreateElement(Xmlns.folderHierarchyXmlns, "FolderSync", Namespaces.folderHierarchyNamespace); folderSyncNode.Prefix = Xmlns.folderHierarchyXmlns; folderSyncXML.AppendChild(folderSyncNode); if (syncKey == "") syncKey = "0"; XmlNode syncKeyNode = folderSyncXML.CreateElement(Xmlns.folderHierarchyXmlns, "SyncKey", Namespaces.folderHierarchyNamespace); syncKeyNode.Prefix = Xmlns.folderHierarchyXmlns; syncKeyNode.InnerText = syncKey; folderSyncNode.AppendChild(syncKeyNode); StringWriter sw = new StringWriter(); XmlTextWriter xmlw = new XmlTextWriter(sw); xmlw.Formatting = Formatting.Indented; folderSyncXML.WriteTo(xmlw); xmlw.Flush(); XmlString = sw.ToString(); }
public static void InsertCDataNodeToDocumentNode() { var xmlDocument = new XmlDocument(); xmlDocument.LoadXml("<a/>"); var cDataSection = xmlDocument.CreateCDataSection("data"); Assert.Throws<InvalidOperationException>(() => xmlDocument.InsertBefore(cDataSection, null)); }
/// <summary> /// Validates the given xml document, throwing an exception if there /// is a validation failure /// </summary> /// <param name="xmlDocument">The xml document in a continuous /// string</param> /// <param name="rootElementName">The root element name</param> /// <param name="dtd">The dtd path</param> /// <exception cref="InvalidXmlDefinitionException">Thrown if there /// is a validation failure</exception> public void ValidateDocument(string xmlDocument, string rootElementName, string dtd) { _xmlDocument = new XmlDocument(); _xmlDocument.LoadXml(xmlDocument); _xmlDocument.InsertBefore(_xmlDocument.CreateDocumentType(rootElementName, null, null, dtd), _xmlDocument.DocumentElement); ValidateCurrentDocument(); }
private XmlDocument LagXmlRotnode() { var xmlDokument = new XmlDocument {PreserveWhitespace = true}; var xmlDeclaration = xmlDokument.CreateXmlDeclaration("1.0", "UTF-8", null); var baseNode = xmlDokument.CreateElement("env", "Envelope", NavneromUtility.SoapEnvelopeEnv12); xmlDokument.AppendChild(baseNode); xmlDokument.InsertBefore(xmlDeclaration, xmlDokument.DocumentElement); return xmlDokument; }
public static XmlDocument CreateXmlDocument(string rootName) { XmlDocument doc = new XmlDocument(); XmlDeclaration decl = doc.CreateXmlDeclaration("1.0", "utf-8", ""); doc.InsertBefore(decl, doc.DocumentElement); XmlNode newNode = doc.CreateElement(rootName); doc.AppendChild(newNode); return doc; }
public void ProcessInputKeyFile(string inputPath, string outputPath, string pass,X509Certificate2 xcert,bool flag,string oneTimePassword ) { string strKey = string.Format("//{0}/{1}", CollectionIDTag, KeyTag); string strID = string.Format("//{0}/{1}", CollectionIDTag, iFolderIDTag); string decKey; byte[] decKeyByteArray; rsadec = xcert.PrivateKey as RSACryptoServiceProvider; try { string inKeyPath = Path.GetFullPath(inputPath); string outKeyPath = Path.GetFullPath(outputPath); XmlDocument encFile = new XmlDocument(); encFile.Load(inKeyPath); XmlNodeList keyNodeList, idNodeList; XmlElement root = encFile.DocumentElement; keyNodeList = root.SelectNodes(strKey); idNodeList = root.SelectNodes(strID); System.Xml.XmlDocument document = new XmlDocument(); XmlDeclaration xmlDeclaration = document.CreateXmlDeclaration("1.0", "utf-8", null); document.InsertBefore(xmlDeclaration, document.DocumentElement); XmlElement title = document.CreateElement(titleTag); document.AppendChild(title); int i = 0; foreach (XmlNode idNode in idNodeList) { if (idNode.InnerText == null || idNode.InnerText == String.Empty) continue; Console.WriteLine(idNode.InnerText); XmlNode newNode = document.CreateNode("element", CollectionIDTag, ""); newNode.InnerText = ""; document.DocumentElement.AppendChild(newNode); XmlNode innerNode = document.CreateNode("element", iFolderIDTag, ""); innerNode.InnerText = idNode.InnerText; newNode.AppendChild(innerNode); { XmlNode keyNode = keyNodeList[i++]; Console.WriteLine(decKey = keyNode.InnerText); decKeyByteArray = Convert.FromBase64String(decKey); XmlNode newElem2 = document.CreateNode("element", KeyTag, ""); if (decKey == null || decKey == String.Empty) continue; if (flag == true) newElem2.InnerText = DecodeMessage(decKeyByteArray, oneTimePassword); else newElem2.InnerText = DecodeMessage(decKeyByteArray); newNode.AppendChild(newElem2); } } if (File.Exists(outKeyPath)) File.Delete(outKeyPath); document.Save(outKeyPath); } catch (Exception e) { Console.WriteLine("Exception while processing" + e.Message + e.StackTrace); } }
public XMLHelper(string fileName, bool hasDeclaration = false) { sFileName = fileName; Document = new XmlDocument(); if (hasDeclaration) { XmlDeclaration xmldecl = Document.CreateXmlDeclaration("1.0", "UTF-8", null); Document.InsertBefore(xmldecl, Document.DocumentElement); } }
public string ew_savepagexml(string pageName, string subFolder, XPathNavigator content) { try { string wikiFolder = getmodulesetting("wikiFolder").ToString(); string pagePath = string.Empty; string sPath = string.Empty; string phisicalRoot = transformer.DnnSettings.P.HomeDirectoryMapPath; // phisical portal home directory if (!phisicalRoot.EndsWith("\\")) { phisicalRoot += "\\"; } //optional subFolder (currently used only for archived versions in "archive" folder) if (subFolder != string.Empty) { sPath = wikiFolder + @"\" + subFolder; } else { sPath = wikiFolder; } //log("Check path " + System.IO.Path.Combine(phisicalRoot, sPath)); if (!Directory.Exists(System.IO.Path.Combine(phisicalRoot, sPath))) { Directory.CreateDirectory(System.IO.Path.Combine(phisicalRoot, sPath)); } pagePath = sPath + @"\" + pageName; if (!pagePath.ToLower().EndsWith(".wiki.xml")) { pagePath += ".wiki.xml"; } System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); XmlDeclaration xmldecl; xmldecl = doc.CreateXmlDeclaration("1.0", null, null); doc.LoadXml(content.OuterXml); XmlElement root = doc.DocumentElement; doc.InsertBefore(xmldecl, root); //log("Save page to " + System.IO.Path.Combine(phisicalRoot, pagePath)); doc.Save(System.IO.Path.Combine(phisicalRoot, pagePath)); return("ok"); } catch (Exception ex) { return(ex.Message); } }