CreateElement() public method

public CreateElement ( String name ) : XmlElement
name String
return XmlElement
Example #1
1
        protected override void SaveNode(XmlDocument xmlDoc, XmlElement nodeElement, SaveContext context)
        {
            Controller.SaveNode(xmlDoc, nodeElement, context);
            
            var outEl = xmlDoc.CreateElement("Name");
            outEl.SetAttribute("value", NickName);
            nodeElement.AppendChild(outEl);

            outEl = xmlDoc.CreateElement("Description");
            outEl.SetAttribute("value", Description);
            nodeElement.AppendChild(outEl);

            outEl = xmlDoc.CreateElement("Inputs");
            foreach (string input in InPortData.Select(x => x.NickName))
            {
                XmlElement inputEl = xmlDoc.CreateElement("Input");
                inputEl.SetAttribute("value", input);
                outEl.AppendChild(inputEl);
            }
            nodeElement.AppendChild(outEl);

            outEl = xmlDoc.CreateElement("Outputs");
            foreach (string output in OutPortData.Select(x => x.NickName))
            {
                XmlElement outputEl = xmlDoc.CreateElement("Output");
                outputEl.SetAttribute("value", output);
                outEl.AppendChild(outputEl);
            }
            nodeElement.AppendChild(outEl);
        }
Example #2
1
        private bool OverWriting() {
        //private async Task<bool> OverWriting() {
            if (ListingQueue.Any()) {
                XmlDocument xmlDoc;
                XmlElement xmlEle;
                XmlNode newNode;

                xmlDoc = new XmlDocument();
                xmlDoc.Load("ImageData.xml"); // XML문서 로딩

                newNode = xmlDoc.SelectSingleNode("Images"); // 추가할 부모 Node 찾기
                xmlEle = xmlDoc.CreateElement("Image");
                newNode.AppendChild(xmlEle);
                newNode = newNode.LastChild;
                xmlEle = xmlDoc.CreateElement("ImagePath"); // 추가할 Node 생성
                xmlEle.InnerText = ListingQueue.Peek();
                ListingQueue.Dequeue();
                newNode.AppendChild(xmlEle); // 위에서 찾은 부모 Node에 자식 노드로 추가..

                xmlDoc.Save("ImageData.xml"); // XML문서 저장..
                xmlDoc = null;

                return true;
            }
            return false;
        }
Example #3
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;
        }
        public static XmlElement GetHttpRuntime(XmlDocument configuration, bool createIfMissing = false)
        {
            var systemWeb = configuration.SelectSingleElement("/configuration/system.web");
              if (systemWeb == null)
              {
            if (!createIfMissing)
            {
              return null;
            }

            systemWeb = configuration.CreateElement("system.web");
            configuration.DocumentElement.AppendChild(systemWeb);
              }

              var httpRuntime = systemWeb.SelectSingleElement("httpRuntime");
              if (httpRuntime != null)
              {
            return httpRuntime;
              }

              if (!createIfMissing)
              {
            return null;
              }

              httpRuntime = configuration.CreateElement("httpRuntime");
              systemWeb.AppendChild(httpRuntime);

              return httpRuntime;
        }
 public void Save(string path)
 {
     this.time = DateTime.Now;
     if (!File.Exists(path))
     {
         XmlWriter writer = XmlWriter.Create(path);
         writer.WriteStartElement("head");
         writer.WriteFullEndElement();
         writer.Close();
     }
     XmlDocument doc = new XmlDocument();
     doc.Load(path);
     XmlNode root = doc.DocumentElement;
     XmlElement newOrder = doc.CreateElement("OrderId");
     XmlElement newUser = doc.CreateElement("UserId");
     XmlElement newTime = doc.CreateElement("Time");
     XmlText orderId = doc.CreateTextNode(this.IdOrder.ToString());
     XmlText userId = doc.CreateTextNode(this.IdUser.ToString());
     XmlText checkTime = doc.CreateTextNode(this.time.ToString("o"));
     newOrder.AppendChild(orderId);
     newUser.AppendChild(userId);
     newTime.AppendChild(checkTime);
     root.InsertAfter(newOrder, root.LastChild);
     root.InsertAfter(newUser, root.LastChild);
     root.InsertAfter(newTime, root.LastChild);
     doc.Save(path);
 }
        public string InvokeResponse(string funcName, List<UPnPArg> args)
        {
            XmlDocument doc = new XmlDocument();
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);
            doc.AppendChild(dec);

            XmlElement env = doc.CreateElement("s", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/");
            doc.AppendChild(env);
            env.SetAttribute("encodingStyle", "http://schemas.xmlsoap.org/soap/envelope/", "http://schemas.xmlsoap.org/soap/encoding/");

            XmlElement body = doc.CreateElement("Body", "http://schemas.xmlsoap.org/soap/envelope/");
            body.Prefix = "s";
            env.AppendChild(body);

            XmlElement func = doc.CreateElement("u", funcName + "Response", "urn:schemas-upnp-org:service:AVTransport:1");
            body.AppendChild(func);
            func.SetAttribute("xmlns:u", "urn:schemas-upnp-org:service:AVTransport:1");

            if (args != null)
            {
                foreach (UPnPArg s in args)
                {
                    XmlElement f = doc.CreateElement(s.ArgName);
                    func.AppendChild(f);
                    f.InnerText = s.ArgVal;
                }
            }

            //Saved for debugging:
            doc.Save(@"InvokeResponse.xml");

            string msg = AppendHead(doc.OuterXml);
            return msg;
        }
        public override string ToText(Subtitle subtitle, string title)
        {
            string xmlStructure = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + Environment.NewLine + "<Subtitle/>";

            XmlDocument xml = new XmlDocument();
            xml.LoadXml(xmlStructure);

            foreach (Paragraph p in subtitle.Paragraphs)
            {
                XmlNode paragraph = xml.CreateElement("Paragraph");

                XmlNode number = xml.CreateElement("Number");
                number.InnerText = p.Number.ToString();
                paragraph.AppendChild(number);

                XmlNode start = xml.CreateElement("StartMilliseconds");
                start.InnerText = p.StartTime.TotalMilliseconds.ToString(CultureInfo.InvariantCulture);
                paragraph.AppendChild(start);

                XmlNode end = xml.CreateElement("EndMilliseconds");
                end.InnerText = p.EndTime.TotalMilliseconds.ToString(CultureInfo.InvariantCulture);
                paragraph.AppendChild(end);

                XmlNode text = xml.CreateElement("Text");
                text.InnerText = HtmlUtil.RemoveHtmlTags(p.Text);
                paragraph.AppendChild(text);

                xml.DocumentElement.AppendChild(paragraph);
            }

            return ToUtf8XmlString(xml);
        }
Example #8
0
		/// <summary>
		/// Implements the following function 
		///		node-set tokenize(string, string)
		/// </summary>
		/// <param name="str"></param>
		/// <param name="delimiters"></param>				
		/// <returns>This function breaks the input string into a sequence of strings, 
		/// treating any character in the list of delimiters as a separator. 
		/// The separators themselves are not returned. 
		/// The tokens are returned as a set of 'token' elements.</returns>
		public XPathNodeIterator tokenize(string str, string delimiters)
		{

			XmlDocument doc = new XmlDocument();
			doc.LoadXml("<tokens/>");

			if (delimiters == String.Empty)
			{
				foreach (char c in str)
				{
					XmlElement elem = doc.CreateElement("token");
					elem.InnerText = c.ToString();
					doc.DocumentElement.AppendChild(elem);
				}
			}
			else
			{
				foreach (string token in str.Split(delimiters.ToCharArray()))
				{

					XmlElement elem = doc.CreateElement("token");
					elem.InnerText = token;
					doc.DocumentElement.AppendChild(elem);
				}
			}

			return doc.CreateNavigator().Select("//token");
		}
Example #9
0
        /// <summary>
        /// Saves the contents of this instance to the defined config file.
        /// </summary>
        /// <param name="force">If false, will only save if the flag indicates that changes have been made. If true, always saves.</param>
        public void Save( bool force = false ) {
            if( force || outOfDate ) {
                Type t = this.GetType();

                PropertyInfo[] properties = t.GetProperties();
                XmlDocument doc = new XmlDocument();
                XmlElement config = doc.CreateElement( "config" );
                lock( threadLock ) {
                    foreach( PropertyInfo pi in properties ) {
                        object val = pi.GetValue( this, null );
                        if( val != null ) {
                            XmlElement element = doc.CreateElement( pi.Name );
                            element.InnerText = val.ToString();
                            config.AppendChild( element );
                        }
                    }
                }
                doc.AppendChild( config );
                try {
                    doc.Save( FilePath );
                } catch( IOException ) {
                }
                outOfDate = false;
            }
        }
Example #10
0
        public void addData(string XmlFilePath,StringBuilder str)
        {
            XmlDocument document = new XmlDocument();

                document.Load(XmlFilePath);
                XmlNode element = document.CreateElement("info");
                document.DocumentElement.AppendChild(element);

                XmlNode title = document.CreateElement("title");
                title.InnerText = XmlFilePath;
                element.AppendChild(title);

                XmlNode chapter = document.CreateElement("chapter");
                document.DocumentElement.AppendChild(chapter); // указываем родителя

                XmlNode para = document.CreateElement("para");
                para.InnerText = str.ToString();
                chapter.AppendChild(para);

                document.Save(XmlFilePath);

               // Console.WriteLine("Data have been added to xml!");

               // Console.ReadKey();
               // Console.WriteLine(XmlToJSON(document));
        }
        public string Subscribe(string deliveryUrl, string eventType)
        {
            string subscriptionId = Guid.NewGuid().ToString();

            XmlDocument subscriptionStore = new XmlDocument();
            subscriptionStore.Load(subscriptionStorePath);

            // Add a new subscription
            XmlNode newSubNode = subscriptionStore.CreateElement("Subscription");

            XmlNode subscriptionIdStart = subscriptionStore.CreateElement("SubscriptionID");
            subscriptionIdStart.InnerText = subscriptionId;
            newSubNode.AppendChild(subscriptionIdStart);

            XmlNode deliveryAddressStart = subscriptionStore.CreateElement("DeliveryAddress");
            deliveryAddressStart.InnerText = deliveryUrl;
            newSubNode.AppendChild(deliveryAddressStart);

            XmlNode eventTypeStart = subscriptionStore.CreateElement("EventType");
            eventTypeStart.InnerText = eventType;
            newSubNode.AppendChild(eventTypeStart);

            subscriptionStore.DocumentElement.AppendChild(newSubNode);

            subscriptionStore.Save(subscriptionStorePath);

            return subscriptionId;
        }
        //Saves given Unistroke to file as a new gesture with name specified
        public static void saveGesture(ref SignalProcessing.Unistroke<double> u, string name)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load("gestures.xml");
            XmlNodeList nl = doc.GetElementsByTagName("gesture_set");
            XmlElement gesture_elem= doc.CreateElement("gesture");
            XmlAttribute ident = doc.CreateAttribute("name");
            ident.InnerText = name;
            gesture_elem.Attributes.Append(ident);

            for(int i = 0; i < u.trace.Count; i++){
                XmlElement n = doc.CreateElement("point");
                XmlAttribute x = doc.CreateAttribute("x");
                XmlAttribute y = doc.CreateAttribute("y");
                XmlAttribute z = doc.CreateAttribute("z");
                x.InnerText = u[i].x.ToString();
                y.InnerText = u[i].y.ToString();
                z.InnerText = u[i].z.ToString();
                n.Attributes.Append(x);
                n.Attributes.Append(y);
                n.Attributes.Append(z);
                gesture_elem.AppendChild(n);
            }

            nl[0].AppendChild(gesture_elem);
            doc.Save("gestures.xml");
        }
Example #13
0
        private void GenerateStrings(string inputPath, string outputFile)
        {
            XElement rootElement = XElement.Load(inputPath);
            IEnumerable<Tuple<string, string>> items = from dataElement in rootElement.Descendants("data")
                                                       let key = dataElement.Attribute("name").Value
                                                       let valueElement = dataElement.Element("value")
                                                       where valueElement != null
                                                       let value = valueElement.Value
                                                       select new Tuple<string, string>(key, value);
            XmlDocument document = new XmlDocument();
            document.AppendChild(document.CreateXmlDeclaration("1.0", "utf-8", null));
            XmlNode rootNode = document.CreateElement("resources");
            document.AppendChild(rootNode);

            foreach (var pair in items)
            {
                XmlNode elementNode = document.CreateElement("string");
                elementNode.InnerText = processValue(pair.Item2);
                XmlAttribute attributeName = document.CreateAttribute("name");
                attributeName.Value = processKey(pair.Item1);
                // ReSharper disable once PossibleNullReferenceException
                elementNode.Attributes.Append(attributeName);

                rootNode.AppendChild(elementNode);
            }

            document.Save(outputFile);
        }
Example #14
0
		public XmlNode GetMacro(int Id, string Login, string Password)
		{
		    if (ValidateCredentials(Login, Password)
                && UserHasAppAccess(DefaultApps.developer.ToString(), Login)) 
			{
				var xmlDoc = new XmlDocument();
				var macro = xmlDoc.CreateElement("macro");
				var m = new cms.businesslogic.macro.Macro(Id);
                macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "id", m.Id.ToString()));
                macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "refreshRate", m.RefreshRate.ToString()));
                macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "useInEditor", m.UseInEditor.ToString()));
                macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "alias", m.Alias));
                macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "name", m.Name));
                macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "assembly", m.Assembly));
                macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "type", m.Type));
                macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "xslt", m.Xslt));
				var properties = xmlDoc.CreateElement("properties");
				foreach (var mp in m.Properties) 
				{
					var pXml = xmlDoc.CreateElement("property");
                    pXml.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "alias", mp.Alias));
                    pXml.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "name", mp.Name));
                    pXml.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "public", mp.Public.ToString()));
					properties.AppendChild(pXml);
				}
				macro.AppendChild(properties);
				return macro;
			}
		    return null;
		}
        /// <summary>
        /// Serializes the specified play list items.
        /// </summary>
        /// <param name="items">The play list.</param>
        /// <returns>The serielized play list as xml document.</returns>
        public XmlDocument Serialize(IEnumerable<ListViewItem> items)
        {
            var doc = new XmlDocument();

            XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "utf-8", "yes");
            doc.AppendChild(declaration);

            XmlElement root = doc.CreateElement("items");
            doc.AppendChild(root);

            foreach (ListViewItem item in items)
            {
                XmlElement element = doc.CreateElement("item");
                element.InnerText = item.Text;

                XmlAttribute startTime = doc.CreateAttribute("start");
                startTime.InnerText = item.SubItems[1].Text;
                element.Attributes.Append(startTime);

                XmlAttribute endTime = doc.CreateAttribute("end");
                endTime.InnerText = item.SubItems[2].Text;
                element.Attributes.Append(endTime);

                XmlAttribute duration = doc.CreateAttribute("duration");
                duration.InnerText = item.SubItems[3].Text;
                element.Attributes.Append(duration);

                root.AppendChild(element);
            }

            return doc;
        }
        //Generate the Terms collection (of Term) based on an xml document
        public static bool Save(XmlDocument xmlTemplateDoc, Template template, bool bValidate)
        {
            //Convert the xml into an xmldocument
            //XmlDocument xmlTemplateDoc = new XmlDocument();
            //xmlTemplateDoc.PreserveWhitespace = false;
            //xmlTemplateDoc.LoadXml(template.TemplateDef);

            //Convert the objects stored in memory to an xmldocument
            XmlDocument xmlDoc = new XmlDocument();
            XmlElement nodeUserDocumentPrinters = xmlDoc.CreateElement(XMLNames._E_UserDocumentPrinters);

            if (template.UserDocumentPrinters != null)
                foreach (Role userDocumentPrinter in template.UserDocumentPrinters)
                {
                    XmlElement nodeUserDocumentPrinter = xmlDoc.CreateElement(XMLNames._E_Role);
                    userDocumentPrinter.Build(xmlDoc, nodeUserDocumentPrinter, bValidate);
                    nodeUserDocumentPrinters.AppendChild(nodeUserDocumentPrinter);
                }

            //Replace the impacted portion of the complete xml with this version from memory
            XmlNode importedNodeUserDocumentPrinters = xmlTemplateDoc.ImportNode(nodeUserDocumentPrinters, true);
            //Find the "Comments" child node
            XmlNode userDocumentPrinterChildNode = xmlTemplateDoc.SelectSingleNode(Utility.XMLHelper.GetXPath(true, XMLNames._E_TemplateDef, XMLNames._E_UserDocumentPrinters));
            if (userDocumentPrinterChildNode != null)
                xmlTemplateDoc.DocumentElement.ReplaceChild(importedNodeUserDocumentPrinters, userDocumentPrinterChildNode);
            else
                xmlTemplateDoc.DocumentElement.AppendChild(importedNodeUserDocumentPrinters);

            return true;
        }
Example #17
0
        /// <summary>
        /// Generates a new floating license.
        /// </summary>
        /// <param name="name">Name of the license holder</param>
        /// <param name="publicKey">public key of the license server</param>
        /// <returns>license content</returns>
        public string GenerateFloatingLicense(string name, string publicKey)
        {
            using (var rsa = Encryptor.Current.CreateAsymmetrical())
            {
                rsa.FromXmlString(privateKey);
                var doc = new XmlDocument();
                var license = doc.CreateElement("floating-license");
                doc.AppendChild(license);

                var publicKeyEl = doc.CreateElement("license-server-public-key");
                license.AppendChild(publicKeyEl);
                publicKeyEl.InnerText = publicKey;

                var nameEl = doc.CreateElement("name");
                license.AppendChild(nameEl);
                nameEl.InnerText = name;

                var signature = GetXmlDigitalSignature(doc, rsa.Algorithm);
                doc.FirstChild.AppendChild(doc.ImportNode(signature, true));

                var ms = new MemoryStream();
                var writer = XmlWriter.Create(ms, new XmlWriterSettings
                {
                    Indent = true,
                    Encoding = Encoding.UTF8
                });
                doc.Save(writer);
                ms.Position = 0;
                return new StreamReader(ms).ReadToEnd();
            }
        }
Example #18
0
        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;
        }
Example #19
0
        public ControlResponse GetResponse(Exception ex)
        {
            var env = new XmlDocument();
            env.AppendChild(env.CreateXmlDeclaration("1.0", "utf-8", "yes"));
            var envelope = env.CreateElement("SOAP-ENV", "Envelope", NS_SOAPENV);
            env.AppendChild(envelope);
            envelope.SetAttribute("encodingStyle", NS_SOAPENV, "http://schemas.xmlsoap.org/soap/encoding/");

            var rbody = env.CreateElement("SOAP-ENV:Body", NS_SOAPENV);
            env.DocumentElement.AppendChild(rbody);

            var fault = env.CreateElement("SOAP-ENV", "Fault", NS_SOAPENV);
            var faultCode = env.CreateElement("faultcode");
            faultCode.InnerText = "500";
            fault.AppendChild(faultCode);
            var faultString = env.CreateElement("faultstring");
            faultString.InnerText = ex.ToString();
            fault.AppendChild(faultString);
            var detail = env.CreateDocumentFragment();
            detail.InnerXml = "<detail><UPnPError xmlns=\"urn:schemas-upnp-org:control-1-0\"><errorCode>401</errorCode><errorDescription>Invalid Action</errorDescription></UPnPError></detail>";
            fault.AppendChild(detail);
            rbody.AppendChild(fault);

            return new ControlResponse
            {
                Xml = env.OuterXml,
                IsSuccessful = false
            };
        }
Example #20
0
        public void CreateXml(string xmlPath, string xmlName, string[] value, string[] xmlElementNode)
        {
            try
            {
                string str = inType.ToString();
                if (str.Length < 5)
                {
                    return;
                }
                string rootName = str.Substring(str.Length - 5, 4);
                XmlDocument doc = new XmlDocument();
                XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
                doc.AppendChild(dec);

                XmlElement root = doc.CreateElement(rootName);
                doc.AppendChild(root);
                XmlNode childElement = doc.CreateElement(str);
                for (int i = 0; i < xmlElementNode.Length; i++)
                {
                    XmlElement xe = doc.CreateElement(xmlElementNode[i]);
                    xe.InnerText = value[i];
                    childElement.AppendChild(xe);
                }
                root.AppendChild(childElement);
                doc.Save(string.Concat(@"", xmlPath, xmlName));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #21
0
        public static void Save(string languageID, NameValueCollection translations)
        {
            string stub = Resource1.ResourceManager.GetString("ResxTemplate");
              string xml = BuildFileName(languageID);
              StreamWriter writer = new StreamWriter(xml, false, Encoding.UTF8);
              writer.Write(stub);
              writer.Close();
              XmlDocument doc = new XmlDocument();
              doc.Load(xml);
              XmlNode nRoot = doc.SelectSingleNode("/root");
              foreach (string key in translations.Keys)
              {
            if (translations[key] == null) continue;
            XmlNode nValue = doc.CreateElement("value");

            nValue.InnerText = translations[key];
            XmlNode nKey = doc.CreateElement("data");
            XmlAttribute attr = nKey.OwnerDocument.CreateAttribute("name");
            attr.InnerText = key;
            nKey.Attributes.Append(attr);
            attr = nKey.OwnerDocument.CreateAttribute("xml:space");
            attr.InnerText = "preserve";
            nKey.Attributes.Append(attr);
            nKey.AppendChild(nValue);
            nRoot.AppendChild(nKey);
              }
              doc.Save(xml);
        }
Example #22
0
        /// <summary>
        /// XML-Datei mit XmlDocument erstellen.
        /// </summary>
        static void CreateXmlDocument()
        {
            XmlDocument xmlDoc = new XmlDocument();
            XmlDeclaration declaration = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", "no");  // XML Deklaration
            xmlDoc.AppendChild(declaration);

            XmlNode rootNode = xmlDoc.CreateElement("books");   // Wurzelelement
            xmlDoc.AppendChild(rootNode);   // Wurzelelement zum Dokument hinzufuegen

            // <book> Element
            XmlNode userNode = xmlDoc.CreateElement("book");
            // mit einem Attribut
            XmlAttribute attribute = xmlDoc.CreateAttribute("release");
            attribute.Value = "2013/02/15";
            userNode.Attributes.Append(attribute);  // Attribut zum <book> Ele hinzufuegen
            // und Textinhalt
            userNode.InnerText = "Elizabeth Corley - Pretty Little Things";
            rootNode.AppendChild(userNode); // Textinhalt zum <book> Ele hinzufuegen

            // und noch ein <book>
            userNode = xmlDoc.CreateElement("book");
            attribute = xmlDoc.CreateAttribute("release");
            attribute.Value = "2011/11/11";
            userNode.Attributes.Append(attribute);
            userNode.InnerText = "Stephen Hawking - A Brief History Of Time";
            rootNode.AppendChild(userNode);

            // XML Dokument speichern
            xmlDoc.Save("xmlDocument_books.xml");   // in ../projectname/bin/debug/
        }
Example #23
0
        public override XmlNode ToXml(XmlDocument doc)
        {
            var root = doc.CreateElement("secDNS:update", "urn:ietf:params:xml:ns:secDNS-1.1");
            root.SetAttribute("xmlns:secDNS", "urn:ietf:params:xml:ns:secDNS-1.1");

            var xsd = doc.CreateAttribute("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance");
            xsd.Value = "urn:ietf:params:xml:ns:secDNS-1.1 secDNS-1.1.xsd";
            root.Attributes.Append(xsd);

            if (ToRemove.Any())
            {
                var removeNode = doc.CreateElement("secDNS:rem", "urn:ietf:params:xml:ns:secDNS-1.1");

                foreach (var data in ToRemove)
                {
                    removeNode.AppendChild(data.ToXml(doc));
                }

                root.AppendChild(removeNode);
            }

            if (ToAdd.Any())
            {
                var addNode = doc.CreateElement("secDNS:add", "urn:ietf:params:xml:ns:secDNS-1.1");

                foreach (var data in ToAdd)
                {
                    addNode.AppendChild(data.ToXml(doc));
                }

                root.AppendChild(addNode);
            }

            return root;
        }
        private void btn_OK_Click(object sender, EventArgs e)
        {
            XmlDocument xmlDoc = new XmlDocument();
            XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
            xmlDoc.AppendChild(docNode);

            XmlNode version = xmlDoc.CreateElement("version");
            xmlDoc.AppendChild(version);

            XmlNode sbtNode = xmlDoc.CreateElement("SBT");
            XmlAttribute sbtAttribute = xmlDoc.CreateAttribute("Path");
            sbtAttribute.Value = textBox1.Text;
            sbtNode.Attributes.Append(sbtAttribute);
            version.AppendChild(sbtNode);

            XmlNode garenaNode = xmlDoc.CreateElement("Garena");
            XmlAttribute garenaAttribute = xmlDoc.CreateAttribute("Path");
            garenaAttribute.Value = textBox2.Text;
            garenaNode.Attributes.Append(garenaAttribute);
            version.AppendChild(garenaNode);

            XmlNode superNode = xmlDoc.CreateElement("Super");
            XmlAttribute superAttribute = xmlDoc.CreateAttribute("Path");
            superAttribute.Value = textBox3.Text;
            superNode.Attributes.Append(superAttribute);
            version.AppendChild(superNode);

            xmlDoc.Save("path");
            this.Close();
        }
Example #25
0
        public void AddItem(string cardKey, string name, string lastname, string username, string password, string XMLFile)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("userdatabase.xml");

            XmlElement newUser = doc.CreateElement("user");

            newUser.SetAttribute("cardkey", cardKey);

            XmlElement newUserName = doc.CreateElement("username");
            newUserName.InnerText = username;
            newUser.AppendChild(newUserName);

            XmlElement newPassword = doc.CreateElement("password");
            newPassword.InnerText = password;
            newUser.AppendChild(newPassword);

            XmlElement newName = doc.CreateElement("name");
            newName.InnerText = name;
            newUser.AppendChild(newName);

            XmlElement newLastName = doc.CreateElement("lastname");
            newLastName.InnerText = lastname;
            newUser.AppendChild(newLastName);

            doc.FirstChild.AppendChild(newUser);

            doc.Save("userdatabase.xml");
        }
Example #26
0
        private void OutputXML(int interval)
        {
            XmlDocument xDoc = new XmlDocument();
            XmlNode xmlEl = xDoc.AppendChild(xDoc.CreateElement("H2G2"));
            xmlEl.Attributes.Append(xDoc.CreateAttribute("TYPE"));
            xmlEl.Attributes["TYPE"].InnerText = "STATUSPAGE";
            xmlEl = xmlEl.AppendChild(xDoc.CreateElement("STATUS-REPORT"));
            xmlEl.AppendChild(xDoc.ImportNode(Statistics.CreateStatisticsDocument(interval).FirstChild, true));

            XmlDocument xmlSignal = new XmlDocument();
            xmlSignal.LoadXml(StringUtils.SerializeToXmlUsingXmlSerialiser(SignalHelper.GetStatus(Global.dnaDiagnostics)));
            xmlEl.AppendChild(xDoc.ImportNode(xmlSignal.DocumentElement, true));

            try
            {
                var memcachedCacheManager = (MemcachedCacheManager)CacheFactory.GetCacheManager("Memcached");
                xmlEl.AppendChild(xDoc.ImportNode(memcachedCacheManager.GetStatsXml(), true));
            }
            catch (Exception e)
            {
                var childNode = xmlEl.AppendChild(xDoc.CreateElement("MEMCACHED_STATUS"));
                childNode.InnerText = "Error getting memcached stats:" + e.Message;
            }

            Response.ContentType = "text/xml";
            Response.Clear();
            Response.Write(xDoc.InnerXml);
            Response.End();
        }
Example #27
0
        protected void Button1_Click(object sender, EventArgs e)
        {

            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(Server.MapPath("Quotes.xml"));
            XmlElement parentelement = xmldoc.CreateElement("Item");

            XmlElement ID = xmldoc.CreateElement("ID");
            ID.InnerText = _txtPN.Value;
            XmlElement QTY = xmldoc.CreateElement("QTY");
            QTY.InnerText = _txtQty.Value;
            XmlElement Product = xmldoc.CreateElement("Product");
            Product.InnerText = _txtProduct.Value;
            XmlElement Cost = xmldoc.CreateElement("Cost");
            Cost.InnerText = _txtCost.Value;

            parentelement.AppendChild(ID);
            parentelement.AppendChild(QTY);
            parentelement.AppendChild(Product);
            parentelement.AppendChild(Cost);
            xmldoc.DocumentElement.AppendChild(parentelement);

            xmldoc.Save(Server.MapPath("Quotes.xml"));
            _txtQty.Value = string.Empty;
            _txtProduct.Value = string.Empty;
            _txtCost.Value = string.Empty;
            _txtPN.Value = string.Empty;

            if (this.IsPostBack)
            {
                this.Get_Xml();
            }

        }
        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;
        }
Example #29
0
        public override string ToText(Subtitle subtitle, string title)
        {
            string xmlStructure =
                "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + Environment.NewLine +
                "<EEG708Captions/>";

            XmlDocument xml = new XmlDocument();
            xml.LoadXml(xmlStructure);

            foreach (Paragraph p in subtitle.Paragraphs)
            {
                XmlNode paragraph = xml.CreateElement("Caption");
                XmlAttribute start = xml.CreateAttribute("timecode");
                start.InnerText = EncodeTimeCode(p.StartTime);
                paragraph.Attributes.Append(start);
                XmlNode text = xml.CreateElement("Text");
                text.InnerText = p.Text;
                paragraph.AppendChild(text);
                xml.DocumentElement.AppendChild(paragraph);

                paragraph = xml.CreateElement("Caption");
                start = xml.CreateAttribute("timecode");
                start.InnerText = EncodeTimeCode(p.EndTime);
                paragraph.Attributes.Append(start);
                xml.DocumentElement.AppendChild(paragraph);
            }

            return ToUtf8XmlString(xml);
        }
        public override string ToText(Subtitle subtitle, string title)
        {
            // <Phrase TimeStart="4020" TimeEnd="6020">
            // <Text>XYZ PRESENTS</Text>
            // </Phrase>
            string xmlStructure = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + Environment.NewLine + "<Subtitle xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"></Subtitle>";

            XmlDocument xml = new XmlDocument();
            xml.LoadXml(xmlStructure);

            int id = 1;
            foreach (Paragraph p in subtitle.Paragraphs)
            {
                XmlNode paragraph = xml.CreateElement("Phrase");

                XmlAttribute start = xml.CreateAttribute("TimeStart");
                start.InnerText = p.StartTime.TotalMilliseconds.ToString();
                paragraph.Attributes.Append(start);

                XmlAttribute duration = xml.CreateAttribute("TimeEnd");
                duration.InnerText = p.EndTime.TotalMilliseconds.ToString();
                paragraph.Attributes.Append(duration);

                XmlNode text = xml.CreateElement("Text");
                text.InnerText = HtmlUtil.RemoveHtmlTags(p.Text).Replace(Environment.NewLine, "\\n");
                paragraph.AppendChild(text);

                xml.DocumentElement.AppendChild(paragraph);
                id++;
            }

            return ToUtf8XmlString(xml);
        }