Example #1
0
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement nodeNode = document.CreateElement("idmef:Node", "http://iana.org/idmef");

            nodeNode.SetAttribute("ident", ident);
            nodeNode.SetAttribute("category", EnumDescription.GetEnumDescription(category));

            if (!string.IsNullOrEmpty(location))
            {
                XmlElement nodeSubNode = document.CreateElement("idmef:location", "http://iana.org/idmef");
                XmlNode subNode = document.CreateNode(XmlNodeType.Text, "idmef", "location", "http://iana.org/idmef");
                subNode.Value = location;
                nodeSubNode.AppendChild(subNode);
                nodeNode.AppendChild(nodeSubNode);
            }
            if (!string.IsNullOrEmpty(name))
            {
                XmlElement nodeSubNode = document.CreateElement("idmef:name", "http://iana.org/idmef");
                XmlNode subNode = document.CreateNode(XmlNodeType.Text, "idmef", "name", "http://iana.org/idmef");
                subNode.Value = name;
                nodeSubNode.AppendChild(subNode);
                nodeNode.AppendChild(nodeSubNode);
            }
            if ((address != null) && (address.Length > 0))
                foreach (var a in address)
                    if (a != null) nodeNode.AppendChild(a.ToXml(document));

            return nodeNode;
        }
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement addressNode = document.CreateElement("idmef:Address", "http://iana.org/idmef");

            addressNode.SetAttribute("ident", ident);
            addressNode.SetAttribute("category", EnumDescription.GetEnumDescription(category));
            if (!string.IsNullOrEmpty(vlanName)) addressNode.SetAttribute("vlan-name", vlanName);
            if (vlanNum != null) addressNode.SetAttribute("vlan-num", vlanNum.ToString());

            if (string.IsNullOrEmpty(address)) throw new InvalidOperationException("Address must have an address node.");
            XmlElement addressSubNode = document.CreateElement("idmef:address", "http://iana.org/idmef");
            XmlNode subNode = document.CreateNode(XmlNodeType.Text, "idmef", "address", "http://iana.org/idmef");
            subNode.Value = address;
            addressSubNode.AppendChild(subNode);
            addressNode.AppendChild(addressSubNode);

            if (!string.IsNullOrEmpty(netmask))
            {
                addressSubNode = document.CreateElement("idmef:netmask", "http://iana.org/idmef");
                subNode = document.CreateNode(XmlNodeType.Text, "idmef", "netmask", "http://iana.org/idmef");
                subNode.Value = netmask;
                addressSubNode.AppendChild(subNode);
                addressNode.AppendChild(addressSubNode);
            }

            return addressNode;
        }
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement addressNode = document.CreateElement("idmef:UserId", "http://iana.org/idmef");

            addressNode.SetAttribute("ident", ident);
            addressNode.SetAttribute("type", EnumDescription.GetEnumDescription(type));
            if (!string.IsNullOrEmpty(tty)) addressNode.SetAttribute("tty", tty);

            if (!string.IsNullOrEmpty(name))
            {
                XmlElement addressSubNode = document.CreateElement("idmef:name", "http://iana.org/idmef");
                XmlNode subNode = document.CreateNode(XmlNodeType.Text, "idmef", "name", "http://iana.org/idmef");
                subNode.Value = name;
                addressSubNode.AppendChild(subNode);
                addressNode.AppendChild(addressSubNode);
            }
            if (number != null)
            {
                XmlElement addressSubNode = document.CreateElement("idmef:number", "http://iana.org/idmef");
                XmlNode subNode = document.CreateNode(XmlNodeType.Text, "idmef", "number", "http://iana.org/idmef");
                subNode.Value = number.ToString();
                addressSubNode.AppendChild(subNode);
                addressNode.AppendChild(addressSubNode);
            }

            return addressNode;
        }
Example #4
0
 private void SaveAsXML()
 {
     DataTable dt = (DataTable)bindingSource.DataSource;
     XmlDocument doc = new XmlDocument();
     XmlNode rootNode = doc.CreateNode(XmlNodeType.Element,"root", null);
     foreach (DataRow row in dt.Rows)
     {
         object[] values = row.ItemArray;
         XmlNode prop = doc.CreateNode(XmlNodeType.Element, "propertyset", null);
         XmlNode name = doc.CreateNode(XmlNodeType.Element, "name", null);
         XmlNode value = doc.CreateNode(XmlNodeType.Element, "value", null);
         name.InnerText = (string)values[0];
         value.InnerText = (string)values[1];
         prop.AppendChild(name);
         prop.AppendChild(value);
         rootNode.AppendChild(prop);
     }
     doc.AppendChild(rootNode);
     string file = Path.Combine(GetExecutingDir(), xmlPropertyFileName);
     if (File.Exists(file))
     {
         File.Delete(file);
     }
     doc.Save(file);
     doc.RemoveAll();
     doc = null;
 }
Example #5
0
 public string AddNewElement(string filePathName, string parent)
 {
     //Here we load the XML file into the memory
     XmlDocument xmlDocument = new XmlDocument();
     xmlDocument.Load(filePathName);
     //Here we create employee node without any namespace
     XmlNode employeeNode = xmlDocument.CreateNode(XmlNodeType.Element, "employee", null);
     //Here we define an attribute and add it to the employee node
     XmlAttribute attribute = xmlDocument.CreateAttribute("id");
     attribute.Value = "e8000";
     employeeNode.Attributes.Append(attribute);
     //Here we create name node without any namespace
     XmlNode nameNode = xmlDocument.CreateNode(XmlNodeType.Element, "name", null);
     nameNode.InnerText = "Arash";
     employeeNode.AppendChild(nameNode);
     //Here we create job node without any namespace
     XmlNode jobNode = xmlDocument.CreateNode(XmlNodeType.Element, "job", null);
     jobNode.InnerText = "Software developer";
     employeeNode.AppendChild(jobNode);
     //Here we select the first element with the name specified by variable parent and
     //append the newly created child to it.
     xmlDocument.SelectSingleNode("//" + parent).AppendChild(employeeNode);
     //Here we save changes to the XML tree permanently.
     xmlDocument.Save(filePathName);
     //Here we retun some information about the file.
     return GetFileInfo(filePathName);
 }
        internal static void Main()
        {
            StreamReader textReader = new StreamReader("../../Person.txt");
            XmlDocument xmlDocument = new XmlDocument();

            XmlNode persons = xmlDocument.CreateNode(XmlNodeType.Element, "persons", string.Empty);

            using (textReader)
            {
                while (!textReader.EndOfStream)
                {
                    XmlNode person = xmlDocument.CreateNode(XmlNodeType.Element, "person", string.Empty);
                    XmlNode personName = xmlDocument.CreateNode(XmlNodeType.Element, "name", string.Empty);
                    XmlNode personAddres = xmlDocument.CreateNode(XmlNodeType.Element, "address", string.Empty);
                    XmlNode personPhone = xmlDocument.CreateNode(XmlNodeType.Element, "phone", string.Empty);

                    personName.InnerText = textReader.ReadLine();
                    personPhone.InnerText = textReader.ReadLine();
                    personAddres.InnerText = textReader.ReadLine();

                    person.AppendChild(personName);
                    person.AppendChild(personAddres);
                    person.AppendChild(personPhone);

                    persons.AppendChild(person);
                }
            }

            xmlDocument.AppendChild(persons);
            xmlDocument.Save("../../saved.xml");
            Console.WriteLine("See results in saved.xml");
        }
        public void LoadData()
        {
            lock (this)
            {
                doc = new XmlDocument();
                if (File.Exists(fileName))
                {
                    XmlTextReader reader = new XmlTextReader(fileName);
                    reader.WhitespaceHandling = WhitespaceHandling.None;
                    doc.Load(reader);
                    reader.Close();
                }
                else
                {
                    createdFile = true;
                    rootNode = doc.CreateNode(XmlNodeType.Element, "Root", String.Empty);
                    doc.AppendChild(rootNode);
                    configNode = doc.CreateNode(XmlNodeType.Element, "Config", String.Empty);
                    rootNode.AppendChild(configNode);
                }

                LoadDataToClass();

                if (createdFile)
                {
                    Commit();
                }
            }
        }
Example #8
0
 private XmlNode Yandex()
 {
     if (DateTime.Now >= _cTemplate.dtNext)
     {
         int nBuild;
         XmlNode cResult;
         XmlNode[] aItems;
         XmlDocument cXmlDocument = new XmlDocument();
         cXmlDocument.LoadXml((new System.Net.WebClient() { Encoding = Encoding.UTF8 }).DownloadString("http://news.yandex.ru/index.rss"));
         nBuild = cXmlDocument.NodeGet("rss/channel/lastBuildDate").InnerText.GetHashCode();
         if (_cTemplate.nBuild != nBuild)
         {
             aItems = cXmlDocument.NodesGet("rss/channel/item", false);
             if (null != aItems)
             {
                 _cTemplate.nBuild = nBuild;
                 cXmlDocument = new XmlDocument();
                 cResult = cXmlDocument.CreateNode(XmlNodeType.Element, "result", null);
                 XmlNode cXNItem;
                 foreach (string sItem in aItems.Select(o => o.NodeGet("title").InnerText).ToArray())
                 {
                     cXNItem = cXmlDocument.CreateNode(XmlNodeType.Element, "item", null);
                     cXNItem.InnerText = sItem.StripTags() + ".    ";
                     cResult.AppendChild(cXNItem);
                 }
                 _cTemplate.cValue = cResult;
                 _cTemplate.dt = DateTime.Now;
             }
             else
                 (new Logger()).WriteWarning("can't get any news from rss");
         }
     }
     return _cTemplate.cValue;
 }
		protected override void LoadStaticConfiguration()
		{
			base.LoadStaticConfiguration();

			Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            string filename = config.FilePath;

            database0 = database1 = "test";

            XmlDocument configDoc = new XmlDocument();
            configDoc.PreserveWhitespace = true;
            configDoc.Load(filename);
            XmlElement configNode = configDoc["configuration"];
            configNode.RemoveAll();

            XmlElement systemData = (XmlElement)configDoc.CreateNode(XmlNodeType.Element, "system.data", "");
            XmlElement dbFactories = (XmlElement)configDoc.CreateNode(XmlNodeType.Element, "DbProviderFactories", "");
            XmlElement provider = (XmlElement)configDoc.CreateNode(XmlNodeType.Element, "add", "");
            provider.SetAttribute("name", "MySQL Data Provider");
            provider.SetAttribute("description", ".Net Framework Data Provider for MySQL");
            provider.SetAttribute("invariant", "MySql.Data.MySqlClient");

            string fullname = String.Format("MySql.Data.MySqlClient.MySqlClientFactory, {0}",
                typeof(MySqlConnection).Assembly.FullName);
            provider.SetAttribute("type", fullname);

            dbFactories.AppendChild(provider);
            systemData.AppendChild(dbFactories);
            configNode.AppendChild(systemData);
            configDoc.Save(filename);

			ConfigurationManager.RefreshSection("system.data");
		}
Example #10
0
        public XmlSecurityRatings()
        {
            _document = new XmlDocument();

            /// _securityRatings = _document.CreateNode(XmlNodeType.Element, "SecurityRatings", XmlSecurityRatings._securityNs);
            _securityRatings = _document.CreateNode(XmlNodeType.Element, "SecurityRatings", null);
            _document.AppendChild(_securityRatings);

            _highSecurity = _document.CreateNode(XmlNodeType.Element, "High", null);
            _securityRatings.AppendChild(_highSecurity);
            appendAttribute(_highSecurity, @"title", @"HIGH RISK");
            appendAttribute(_highSecurity, @"comment", @"This document contains high risk elements");
            appendAttribute(_highSecurity, @"color", @"#B14343");
            appendAttribute(_highSecurity, @"include-in-summary", @"yes");
            appendAttribute(_highSecurity, @"hiddendata", @"This document contains high risk hidden data");
            appendAttribute(_highSecurity, @"contentpolicy", @"This document contains high risk content policy violations");

            _mediumSecurity = _document.CreateNode(XmlNodeType.Element, "Medium", null);
            _securityRatings.AppendChild(_mediumSecurity);
            appendAttribute(_mediumSecurity, @"title", @"MEDIUM RISK");
            appendAttribute(_mediumSecurity, @"comment", @"This document contains medium risk elements");
            appendAttribute(_mediumSecurity, @"color", @"#F0C060");
            appendAttribute(_mediumSecurity, @"include-in-summary", @"yes");
            appendAttribute(_mediumSecurity, @"hiddendata", @"This document contains medium risk hidden data");
            appendAttribute(_mediumSecurity, @"contentpolicy", @"This document contains medium risk content policy violations");

            _lowSecurity = _document.CreateNode(XmlNodeType.Element, "Low", null);
            _securityRatings.AppendChild(_lowSecurity);
            appendAttribute(_lowSecurity, @"title", @"LOW RISK");
            appendAttribute(_lowSecurity, @"comment", @"This document contains normal elements");
            appendAttribute(_lowSecurity, @"color", @"#4E7C49");
            appendAttribute(_lowSecurity, @"include-in-summary", @"no");
            appendAttribute(_lowSecurity, @"hiddendata", @"This document contains low risk hidden data");
            appendAttribute(_lowSecurity, @"contentpolicy", @"This document contains low risk content policy violations");
        }
        public static XmlDocument CreateXMLDocument()
        {
            XmlDocument doc = new XmlDocument();
            XmlNode docNode = doc.CreateXmlDeclaration("1.0", null, null);
            doc.AppendChild(docNode);

            XmlNode configurationNode = doc.CreateElement("Configuration");
            doc.AppendChild(configurationNode);

            XmlNode hostNode = doc.CreateNode(XmlNodeType.Element, "host", "");
            hostNode.InnerText = "https://testserver.datacash.com/Transaction";
            XmlNode timeoutNode = doc.CreateNode(XmlNodeType.Element, "timeout", "");
            timeoutNode.InnerText = "500";
            XmlNode proxyNode = doc.CreateNode(XmlNodeType.Element, "proxy", "");
            proxyNode.InnerText = "http://bloxx.dfguk.com:8080";
            XmlNode logfileNode = doc.CreateNode(XmlNodeType.Element, "logfile", "");
            logfileNode.InnerText = @"C:\Inetpub\wwwroot\WSDataCash\log.txt";
            XmlNode loggingNode = doc.CreateNode(XmlNodeType.Element, "logging", "");
            loggingNode.InnerText = "1";

            configurationNode.AppendChild(hostNode);
            configurationNode.AppendChild(timeoutNode);
            configurationNode.AppendChild(proxyNode);
            configurationNode.AppendChild(logfileNode);
            configurationNode.AppendChild(loggingNode);

            return doc;
        }
        public XmlElement ToXml(XmlDocument document)
        {
            if (string.IsNullOrEmpty(program)) throw new InvalidOperationException("There must be a program node.");

            XmlElement alertNode = document.CreateElement("idmef:OverflowAlert", "http://iana.org/idmef");

            XmlElement subNode = document.CreateElement("idmef:program", "http://iana.org/idmef");
            XmlNode subNodeText = document
                .CreateNode(XmlNodeType.Text, "idmef", "program", "http://iana.org/idmef");
            subNodeText.Value = program;
            subNode.AppendChild(subNodeText);
            alertNode.AppendChild(subNode);
            if (size != null)
            {
                subNode = document.CreateElement("idmef:size", "http://iana.org/idmef");
                subNodeText = document.CreateNode(XmlNodeType.Text, "idmef", "size", "http://iana.org/idmef");
                subNodeText.Value = size.ToString();
                subNode.AppendChild(subNodeText);
                alertNode.AppendChild(subNode);
            }
            if ((buffer != null) && (buffer.Length > 0))
            {
                subNode = document.CreateElement("idmef:buffer", "http://iana.org/idmef");
                subNodeText = document.CreateNode(XmlNodeType.Text, "idmef", "buffer", "http://iana.org/idmef");
                subNodeText.Value = Convert.ToBase64String(buffer);
                subNode.AppendChild(subNodeText);
                alertNode.AppendChild(subNode);
            }

            return alertNode;
        }
        public void AddAttachmentPlaceHolder(string actualPath, string placeholderPath)
        {
            var placeholderDocument = new XmlDocument();

			placeholderDocument.CreateXmlDeclaration("1.0", "utf-16", "yes");

            XmlNode rootNode = placeholderDocument.CreateNode(XmlNodeType.Element, "ManagedAttachment", string.Empty);
            XmlNode actualPathNode = placeholderDocument.CreateNode(XmlNodeType.Element, "ActualPath", string.Empty);
            XmlNode placeholderNode = placeholderDocument.CreateNode(XmlNodeType.Element, "PlaceholderPath",
                                                                     string.Empty);

            actualPathNode.InnerText = actualPath;
            placeholderNode.InnerText = placeholderPath;

            rootNode.AppendChild(actualPathNode);
            rootNode.AppendChild(placeholderNode);

            placeholderDocument.AppendChild(rootNode);

            using (var ms = new MemoryStream())
            {
                ms.Position = 0;
                placeholderDocument.Save(ms);
                ms.Flush();

                ms.Position = 0;
                var sr = new StreamReader(ms);
                string xml = sr.ReadToEnd();

                string filecontents = LargeAttachmentHelper.FileTag + xml;
				File.WriteAllText(placeholderPath, filecontents, Encoding.Unicode);
            }
        }
Example #14
0
        public string CreatingFile(XMLMovieProperties objMovie)
        {
            try
            {
                if (objMovie == null) return null;

                BlobStorageService _blobStorageService = new BlobStorageService();
                XmlDocument documnet = new XmlDocument();

                string fileName = "MovieList-" + objMovie.Month.Substring(0, 3) + "-" + objMovie.Year.ToString() + ".xml";
                string existFileContent = _blobStorageService.GetUploadeXMLFileContent(BlobStorageService.Blob_XMLFileContainer, fileName);

                if (!string.IsNullOrEmpty(existFileContent))
                {
                    documnet.LoadXml(existFileContent);

                    var oldMonth = documnet.SelectSingleNode("Movies/Month[@name='" + objMovie.Month + "']");

                    var oldMovie = oldMonth.SelectSingleNode("Movie[@name='" + objMovie.MovieName + "']");

                    if (oldMovie == null)
                        oldMonth.AppendChild(AddMovieNode(documnet, objMovie));
                    else
                    {
                        oldMonth.RemoveChild(oldMovie);
                        oldMonth.AppendChild(AddMovieNode(documnet, objMovie));
                    }
                }
                else
                {
                    XmlNode root = documnet.CreateNode(XmlNodeType.Element, "Movies", "");

                    XmlAttribute movieYear = documnet.CreateAttribute("year");
                    movieYear.Value = objMovie.Year.ToString();
                    root.Attributes.Append(movieYear);

                    XmlNode month = documnet.CreateNode(XmlNodeType.Element, "Month", "");

                    XmlAttribute monthName = documnet.CreateAttribute("name");
                    monthName.Value = objMovie.Month.ToString();
                    month.Attributes.Append(monthName);

                    month.AppendChild(AddMovieNode(documnet, objMovie));
                    root.AppendChild(month);
                    documnet.AppendChild(root);
                }

                _blobStorageService.UploadXMLFileOnBlob(BlobStorageService.Blob_XMLFileContainer, fileName, documnet.OuterXml);

                return documnet.OuterXml;
                //return fileName;
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                return "";
            }
        }
 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 XmlNode BuildRuleItem(XmlDocument xmlDoc)
		{
			XmlNode nodeRuleItem = xmlDoc.CreateNode(XmlNodeType.Element, XMLNames._E_RuleItem, XMLNames._M_NameSpaceURI);
			Utility.XMLHelper.AddText(xmlDoc, nodeRuleItem, _keyValue);
			XmlNode nodeRuleItemDetails = xmlDoc.CreateNode(XmlNodeType.Element, XMLNames._E_RuleItemDetails, XMLNames._M_NameSpaceURI);
			nodeRuleItem.AppendChild(nodeRuleItemDetails);
			foreach (ExternalInterfaceSearchCriteriaDetail detail in _details)
				nodeRuleItemDetails.AppendChild(detail.BuildRuleItemDetail(xmlDoc));
			return nodeRuleItem;			
		}
Example #17
0
 public static SoapException RaiseException(string uri,
                             string webServiceNamespace,
                             string errorMessage,
                             string errorNumber,
                             string errorSource,
                             FaultCode code)
 {
     XmlQualifiedName faultCodeLocation = null;
     //Identify the location of the FaultCode
     switch (code)
     {
         case FaultCode.Client:
             faultCodeLocation = SoapException.ClientFaultCode;
             break;
         case FaultCode.Server:
             faultCodeLocation = SoapException.ServerFaultCode;
             break;
     }
     XmlDocument xmlDoc = new XmlDocument();
     //Create the Detail node
     XmlNode rootNode = xmlDoc.CreateNode(XmlNodeType.Element,
                        SoapException.DetailElementName.Name,
                        SoapException.DetailElementName.Namespace);
     //Build specific details for the SoapException
     //Add first child of detail XML element.
     XmlNode errorNode = xmlDoc.CreateNode(XmlNodeType.Element, "Error",
                                           webServiceNamespace);
     //Create and set the value for the ErrorNumber node
     XmlNode errorNumberNode =
       xmlDoc.CreateNode(XmlNodeType.Element, "ErrorNumber",
                         webServiceNamespace);
     errorNumberNode.InnerText = errorNumber;
     //Create and set the value for the ErrorMessage node
     XmlNode errorMessageNode = xmlDoc.CreateNode(XmlNodeType.Element,
                                                 "ErrorMessage",
                                                 webServiceNamespace);
     errorMessageNode.InnerText = errorMessage;
     //Create and set the value for the ErrorSource node
     XmlNode errorSourceNode =
       xmlDoc.CreateNode(XmlNodeType.Element, "ErrorSource",
                         webServiceNamespace);
     errorSourceNode.InnerText = errorSource;
     //Append the Error child element nodes to the root detail node.
     errorNode.AppendChild(errorNumberNode);
     errorNode.AppendChild(errorMessageNode);
     errorNode.AppendChild(errorSourceNode);
     //Append the Detail node to the root node
     rootNode.AppendChild(errorNode);
     //Construct the exception
     SoapException soapEx = new SoapException(errorMessage,
                                              faultCodeLocation, uri,
                                              rootNode);
     //Raise the exception  back to the caller
     return soapEx;
 }
Example #18
0
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement inodeNode = document.CreateElement("idmef:Inode", "http://iana.org/idmef");

            if (changeTime != null)
            {
                XmlElement inodeSubNode = document.CreateElement("idmef:change-time", "http://iana.org/idmef");
                XmlNode subNode = document.CreateNode(XmlNodeType.Text, "idmef", "change-time", "http://iana.org/idmef");
                subNode.Value = ((DateTime)changeTime).ToString("o");
                inodeSubNode.AppendChild(subNode);
                inodeNode.AppendChild(inodeSubNode);
            }
            if (number != null)
            {
                XmlElement inodeSubNode = document.CreateElement("idmef:number", "http://iana.org/idmef");
                XmlNode subNode = document.CreateNode(XmlNodeType.Text, "idmef", "number", "http://iana.org/idmef");
                subNode.Value = number.ToString();
                inodeSubNode.AppendChild(subNode);
                inodeNode.AppendChild(inodeSubNode);
            }
            if (majorDevice != null)
            {
                XmlElement inodeSubNode = document.CreateElement("idmef:major-device", "http://iana.org/idmef");
                XmlNode subNode = document.CreateNode(XmlNodeType.Text, "idmef", "major-device", "http://iana.org/idmef");
                subNode.Value = majorDevice.ToString();
                inodeSubNode.AppendChild(subNode);
                inodeNode.AppendChild(inodeSubNode);
            }
            if (minorDevice != null)
            {
                XmlElement inodeSubNode = document.CreateElement("idmef:minor-device", "http://iana.org/idmef");
                XmlNode subNode = document.CreateNode(XmlNodeType.Text, "idmef", "minor-device", "http://iana.org/idmef");
                subNode.Value = minorDevice.ToString();
                inodeSubNode.AppendChild(subNode);
                inodeNode.AppendChild(inodeSubNode);
            }
            if (cMajorDevice != null)
            {
                XmlElement inodeSubNode = document.CreateElement("idmef:c-major-device", "http://iana.org/idmef");
                XmlNode subNode = document.CreateNode(XmlNodeType.Text, "idmef", "c-major-device", "http://iana.org/idmef");
                subNode.Value = cMajorDevice.ToString();
                inodeSubNode.AppendChild(subNode);
                inodeNode.AppendChild(inodeSubNode);
            }
            if (cMinorDevice != null)
            {
                XmlElement inodeSubNode = document.CreateElement("idmef:c-minor-device", "http://iana.org/idmef");
                XmlNode subNode = document.CreateNode(XmlNodeType.Text, "idmef", "c-minor-device", "http://iana.org/idmef");
                subNode.Value = cMinorDevice.ToString();
                inodeSubNode.AppendChild(subNode);
                inodeNode.AppendChild(inodeSubNode);
            }

            return inodeNode;
        }
Example #19
0
 private static XmlNode CreateDValueNodeWithValue(double value)
 {
     var doc = new XmlDocument();
     var node = doc.CreateNode(XmlNodeType.Element, AstConstants.Node, AstConstants.Nodes.Scalar_DNumber, "");
     var valueNode = doc.CreateNode(XmlNodeType.Element, AstConstants.Subnode, AstConstants.Subnodes.Value, "");
     var floatNode = doc.CreateNode(XmlNodeType.Element, AstConstants.Scalar, AstConstants.Scalars.Float, "");
     floatNode.InnerText = value.ToString(CultureInfo.InvariantCulture);
     valueNode.AppendChild(floatNode);
     node.AppendChild(valueNode);
     return node;
 }
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement processNode = document.CreateElement("idmef:Process", "http://iana.org/idmef");

            processNode.SetAttribute("ident", ident);

            if (string.IsNullOrEmpty(name)) throw new ArgumentException("Process must have a name node.");

            XmlElement processSubNode = document.CreateElement("idmef:name", "http://iana.org/idmef");
            XmlNode subNode = document.CreateNode(XmlNodeType.Text, "idmef", "name", "http://iana.org/idmef");
            subNode.Value = name;
            processSubNode.AppendChild(subNode);
            processNode.AppendChild(processSubNode);
            if (pid != null)
            {
                processSubNode = document.CreateElement("idmef:pid", "http://iana.org/idmef");
                subNode = document.CreateNode(XmlNodeType.Text, "idmef", "pid", "http://iana.org/idmef");
                subNode.Value = pid.ToString();
                processSubNode.AppendChild(subNode);
                processNode.AppendChild(processSubNode);
            }
            if (!string.IsNullOrEmpty(path))
            {
                processSubNode = document.CreateElement("idmef:path", "http://iana.org/idmef");
                subNode = document.CreateNode(XmlNodeType.Text, "idmef", "path", "http://iana.org/idmef");
                subNode.Value = path;
                processSubNode.AppendChild(subNode);
                processNode.AppendChild(processSubNode);
            }
            if ((arg != null) && (arg.Length > 0))
                foreach (var a in arg)
                    if (!string.IsNullOrEmpty(a))
                    {
                        processSubNode = document.CreateElement("idmef:arg", "http://iana.org/idmef");
                        subNode = document.CreateNode(XmlNodeType.Text, "idmef", "arg", "http://iana.org/idmef");
                        subNode.Value = a;
                        processSubNode.AppendChild(subNode);
                        processNode.AppendChild(processSubNode);
                    }
            if ((env != null) && (env.Length > 0))
                foreach (var e in env)
                    if (!string.IsNullOrEmpty(e))
                    {
                        processSubNode = document.CreateElement("idmef:env", "http://iana.org/idmef");
                        subNode = document.CreateNode(XmlNodeType.Text, "idmef", "env", "http://iana.org/idmef");
                        subNode.Value = e;
                        processSubNode.AppendChild(subNode);
                        processNode.AppendChild(processSubNode);
                    }

            return processNode;
        }
Example #21
0
 public static void SetValue(string AppKey, string AppValue, bool tt)
 {
     XmlDocument document = new XmlDocument();
     XmlNode node = document.CreateNode(XmlNodeType.Element, "configuration", "");
     document.AppendChild(node);
     XmlNode node2 = document.CreateNode(XmlNodeType.Element, "appSettings", "");
     node.AppendChild(node2);
     XmlElement newChild = document.CreateElement("add");
     newChild.SetAttribute("key", AppKey);
     newChild.SetAttribute("value", AppValue);
     node2.AppendChild(newChild);
     document.Save(System.AppDomain.CurrentDomain.BaseDirectory + "LrcSet.xml");
 }
Example #22
0
        private void Init(string rootName)
        {
            try
            {
                doc = new XmlDocument();

                var dec = doc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
                doc.InsertAfter(dec, null);
                root = doc.CreateNode(XmlNodeType.Element, rootName, "");
                doc.InsertAfter(root, dec);
            }
            catch { }
        }
Example #23
0
        public static XmlDocument GetErrorDocument(string errormessage)
        {
            XmlDocument errorDoc = new XmlDocument();

            errorDoc.AppendChild(errorDoc.CreateProcessingInstruction("xml-stylesheet", "type='text/xsl' href='xsl/errorPage.xsl'"));
            XmlNode root = errorDoc.AppendChild(errorDoc.CreateNode(XmlNodeType.Element, "root", null));
            XmlNode node = root.AppendChild(errorDoc.CreateNode(XmlNodeType.Element, "message", null));

            node.InnerText = errormessage;

            Timingutil.info("Compile Error ! , generate ErrorDom");
            return errorDoc;
        }
Example #24
0
        public XmlNode AddSubEntity(TreeNode treeNode, XmlDocument document)
        {
            Entity entity = EntityDictionary[treeNode.Text];

            XmlNode xmlNode = document.CreateNode(XmlNodeType.Element, "Item", null);
            XmlAttribute attribute = document.CreateAttribute("Name");
            attribute.Value = entity.Name;

            xmlNode.Attributes.Append(attribute);

            if (entity.Parameters.Count > 0)
            {
                XmlNode parameterContainerNode = document.CreateNode(XmlNodeType.Element, "Parameters", null);

                foreach (Entity.Parameter parameter in entity.Parameters)
                {
                    //Create Node for the parameter
                    XmlNode parameterNode = document.CreateNode(XmlNodeType.Element, "Parameter", null);

                    //Create an attribute containing the type
                    XmlAttribute parameterType = document.CreateAttribute("Type");
                    parameterType.Value = parameter.Type.ToString();

                    //Set the inner text to the name of the parameter
                    parameterNode.InnerText = parameter.Name;

                    //add the attribute to the node
                    parameterNode.Attributes.Append(parameterType);

                    //add the parameter node to the parameterContainer
                    parameterContainerNode.AppendChild(parameterNode);

                }

                xmlNode.AppendChild(parameterContainerNode);
            }

            if (treeNode.Nodes.Count > 0)
            {
                XmlNode subEntities = document.CreateNode(XmlNodeType.Element, "SubEntities", null);

                foreach (TreeNode subTreeNode in treeNode.Nodes)
                {
                    subEntities.AppendChild(AddSubEntity(subTreeNode, document));
                }

                xmlNode.AppendChild(subEntities);
            }

            return xmlNode;
        }
Example #25
0
 public RolesDataSource(string rolesFile, string application)
 {
     this._rolesFile = rolesFile;
     this.ApplicationName = application;
     this._agent = new FileAgent();
     if (!this._agent.HasKey(rolesFile))
     {
         XmlDocument doc = new XmlDocument();
         doc.AppendChild(doc.CreateNode(XmlNodeType.XmlDeclaration, "", ""));
         doc.AppendChild(doc.CreateNode(XmlNodeType.Element, "roles", ""));
         this._agent.Write(this._rolesFile, string.Empty);
         this.SaveRolesFile(doc);
     }
 }
Example #26
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            String strAddinPath = Path.GetDirectoryName(FAddIn.Object.GetType().Assembly.Location) + "\\ServerPath.xml";
            if (!File.Exists(strAddinPath))
            {
                FileStream fs = File.Open(strAddinPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine("<Infolight></Infolight>");
                sw.Close();
                fs.Close();
                XmlDocument x = new XmlDocument();
                x.Load(strAddinPath);
                XmlNode xn = x.CreateNode(XmlNodeType.Element, "ServerPath", "");
                XmlAttribute xa = x.CreateAttribute("Value");
                xa.Value = this.tbServerPath.Text;

                xn.Attributes.Append(xa);
                x.ChildNodes[0].AppendChild(xn);

                xn = x.CreateNode(XmlNodeType.Element, "WebClientPath", "");
                xa = x.CreateAttribute("Value");
                xa.Value = this.tbWebClientPath.Text;

                xn.Attributes.Append(xa);
                x.ChildNodes[0].AppendChild(xn);
                x.Save(strAddinPath);
            }
            else
            {
                XmlDocument x = new XmlDocument();
                x.Load(strAddinPath);
                x.FirstChild.ChildNodes[0].Attributes["Value"].Value = this.tbServerPath.Text;

                if (x.FirstChild.ChildNodes.Count < 2)
                {
                    XmlNode xn = x.CreateNode(XmlNodeType.Element, "WebClientPath", "");
                    XmlAttribute xa = x.CreateAttribute("Value");
                    xa.Value = this.tbWebClientPath.Text;
                    xn.Attributes.Append(xa);
                    x.ChildNodes[0].AppendChild(xn);
                }
                else
                {
                    x.FirstChild.ChildNodes[1].Attributes["Value"].Value = this.tbWebClientPath.Text;
                }
                x.Save(strAddinPath);
            }
            this.Hide();
        }
Example #27
0
        static void Main(string[] args)
        {
            XmlDocument xmlDoc = new XmlDocument();
            XmlNode xmlNode;
            xmlNode = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
            xmlDoc.AppendChild(xmlNode);

            XmlNode root = xmlDoc.CreateElement("urlset");
            xmlDoc.AppendChild(root);

            using (SqlConnection conn = new SqlConnection(connectionstring))
            {
                SqlCommand cmd = new SqlCommand("select idkey from feature", conn);
                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    XmlNode url = xmlDoc.CreateNode(XmlNodeType.Element, "url", null);
                    root.AppendChild(url);

                    xmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "loc", null);
                    xmlNode.InnerText = string.Format("http://www.culture-visions.com/f/{0}.html", Base64.Encode(reader.GetInt32(0).ToString()));
                    url.AppendChild(xmlNode);

                    xmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "lastmod", null);
                    xmlNode.InnerText = "2011-07-25";
                    url.AppendChild(xmlNode);

                    xmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "priority", null);
                    xmlNode.InnerText = "0.5";
                    url.AppendChild(xmlNode);
                }

                reader.Close();

                cmd = new SqlCommand("select idkey,aired from webcast order by aired desc", conn);
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    XmlNode url = xmlDoc.CreateNode(XmlNodeType.Element, "url", null);
                    root.AppendChild(url);

                    xmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "loc", null);
                    xmlNode.InnerText = string.Format("http://www.culture-visions.com/w/{0}.html", Base64.Encode(reader.GetInt32(0).ToString()));
                    url.AppendChild(xmlNode);

                    xmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "lastmod", null);
                    xmlNode.InnerText = reader.GetDateTime(1).ToString("yyyy-MM-dd");
                    url.AppendChild(xmlNode);

                    xmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "priority", null);
                    xmlNode.InnerText = "0.8";
                    url.AppendChild(xmlNode);
                }
            }

            xmlDoc.Save(@"E:\sitemap.xml");
        }
        static XmlDocument AddOrModifyAppSettings(XmlDocument xmlDoc, string key, string value)
        {
            bool isNew = false;

            XmlNodeList list = xmlDoc.DocumentElement.SelectNodes(string.Format("appSettings/add[@key='{0}']", key));
            XmlNode node;
            isNew = list.Count == 0;
            if (isNew)
            {
                node = xmlDoc.CreateNode(XmlNodeType.Element, "add", null);
                XmlAttribute attribute = xmlDoc.CreateAttribute("key");
                attribute.Value = key;
                node.Attributes.Append(attribute);

                attribute = xmlDoc.CreateAttribute("value");
                attribute.Value = value;
                node.Attributes.Append(attribute);

                xmlDoc.DocumentElement.SelectNodes("appSettings")[0].AppendChild(node);
            }
            else
            {
                node = list[0];
                node.Attributes["value"].Value = value;
            }
            return xmlDoc;
        }
Example #29
0
        private string GetXML()
        {
            XmlDocument document = new XmlDocument();

            XmlElement RazaoNode = document.CreateElement("Razao");
            RazaoNode.InnerText = Razao;

            XmlElement ValoresNode = document.CreateElement("Valores");
            XmlElement ValorNode = document.CreateElement("Valor");

            XmlAttribute moeda = document.CreateAttribute("moeda");
            moeda.Value = "BRL";

            ValorNode.Attributes.Append(moeda);
            ValorNode.InnerText = String.Format("{0:0.00}", Valor).Replace(',','.');

            ValoresNode.AppendChild(ValorNode);

            XmlNode EnviarInstrucao = document.CreateElement("EnviarInstrucao");
            XmlNode InstrucaoUnica = EnviarInstrucao.AppendChild(document.CreateNode(XmlNodeType.Element, "InstrucaoUnica", ""));

            InstrucaoUnica.AppendChild(RazaoNode);
            InstrucaoUnica.AppendChild(ValoresNode);

            return EnviarInstrucao.OuterXml;
        }
        internal static XElement ToXml(this Property property, IDataTypeService dataTypeService)
        {
            var nodeName = UmbracoSettings.UseLegacyXmlSchema ? "data" : property.Alias.ToSafeAlias();

            var xd = new XmlDocument();
            var xmlNode = xd.CreateNode(XmlNodeType.Element, nodeName, "");

            //Add the property alias to the legacy schema
            if (UmbracoSettings.UseLegacyXmlSchema)
            {
                var alias = xd.CreateAttribute("alias");
                alias.Value = property.Alias.ToSafeAlias();
                xmlNode.Attributes.Append(alias);
            }

            //This seems to fail during testing 
            //SD: With the new null checks below, this shouldn't fail anymore.
            var dt = property.PropertyType.DataType(property.Id, dataTypeService);
            if (dt != null && dt.Data != null)
            {
                //We've already got the value for the property so we're going to give it to the 
                // data type's data property so it doesn't go re-look up the value from the db again.
                var defaultData = dt.Data as IDataValueSetter;
                if (defaultData != null)
                {
                    defaultData.SetValue(property.Value, property.PropertyType.DataTypeDatabaseType.ToString());
                }

                xmlNode.AppendChild(dt.Data.ToXMl(xd));
            }

            var element = xmlNode.GetXElement();
            return element;
        }