CreateTextNode() public method

public CreateTextNode ( String text ) : XmlText
text String
return XmlText
        public XmlDocument GenerateForGenerateSolution(string platform, IEnumerable<XmlElement> projectElements)
        {
            var doc = new XmlDocument();
            doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", null));
            var input = doc.CreateElement("Input");
            doc.AppendChild(input);

            var generation = doc.CreateElement("Generation");
            var platformName = doc.CreateElement("Platform");
            platformName.AppendChild(doc.CreateTextNode(platform));
            var hostPlatformName = doc.CreateElement("HostPlatform");
            hostPlatformName.AppendChild(doc.CreateTextNode(_hostPlatformDetector.DetectPlatform()));
            generation.AppendChild(platformName);
            generation.AppendChild(hostPlatformName);
            input.AppendChild(generation);

            var featuresNode = doc.CreateElement("Features");
            foreach (var feature in _featureManager.GetAllEnabledFeatures())
            {
                var featureNode = doc.CreateElement(feature.ToString());
                featureNode.AppendChild(doc.CreateTextNode("True"));
                featuresNode.AppendChild(featureNode);
            }
            input.AppendChild(featuresNode);

            var projects = doc.CreateElement("Projects");
            input.AppendChild(projects);

            foreach (var projectElem in projectElements)
            {
                projects.AppendChild(doc.ImportNode(projectElem, true));
            }

            return doc;
        }
Example #2
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 #3
0
        /// <summary>
        /// Write a log into the xml file
        /// </summary>
        /// <param name="log"></param>
        public void writeLog(string log)
        {
            string xmlName = "record.xml";
            if (!System.IO.File.Exists(xmlName))
            {
                XmlTextWriter writer = new XmlTextWriter(xmlName, System.Text.Encoding.UTF8);
                writer.WriteStartDocument(true);
                writer.Formatting = Formatting.Indented;
                writer.Indentation = 2;

                writer.WriteStartElement("Record");
                writer.WriteEndElement();

                writer.WriteEndDocument();//End
                writer.Close();
            }
            XmlDocument doc = new XmlDocument();
            doc.Load(xmlName);
            XmlElement root = doc.DocumentElement;
            XmlElement elementRecord = doc.CreateElement("record");
            XmlElement elementTime = doc.CreateElement("time");
            XmlElement elementEvent = doc.CreateElement("event");
            XmlText time = doc.CreateTextNode(getSystemTime());
            XmlText myevent = doc.CreateTextNode(log);
            elementRecord.AppendChild(elementTime);
            elementRecord.AppendChild(elementEvent);
            elementTime.AppendChild(time);
            elementEvent.AppendChild(myevent);
            root.InsertAfter(elementRecord, root.LastChild);
            doc.Save(xmlName);
        }
Example #4
0
        public override void SetUp()
        {
            mConfig = new mConfig();
            configSection = new XmlDocument();
            //an xml declaration is needed to be treated as xml, but the xml section that is passed to mConfig.Create() in
            //actual use is missing it.
            //			XmlDeclaration xmlDeclaration = configSection.CreateXmlDeclaration("1.0", "utf-8", null);
            //			configSection.InsertBefore(xmlDeclaration, configSection.DocumentElement);
            XmlElement root = configSection.CreateElement("m");
            configSection.AppendChild(root);

            XmlElement element1 = configSection.CreateElement("MusicDirectory");
            root.AppendChild(element1);
            element1.AppendChild(configSection.CreateTextNode("Directory One"));
            XmlElement element2 = configSection.CreateElement("MusicDirectory");
            root.AppendChild(element2);
            element2.AppendChild(configSection.CreateTextNode("Directory Two"));

            XmlElement element3 = configSection.CreateElement("MusicDirectory");
            root.AppendChild(element3);
            element3.AppendChild(configSection.CreateTextNode("Directory Three"));

            XmlElement element4 = configSection.CreateElement("SomeOtherElement");
            root.AppendChild(element4);
            element4.AppendChild(configSection.CreateTextNode("Not a directory"));
        }
        public XmlDocument getAccessRequest()
        {
            XmlDocument outDoc = new XmlDocument();
            XmlDeclaration xmlDec = outDoc.CreateXmlDeclaration("1.0", "utf-8", null);

            try
            {
                XmlElement root = outDoc.CreateElement("AccessRequest");
                root.SetAttribute("xml:lang", "en-US");
                outDoc.AppendChild(root);

                XmlElement accessLicenseNumber = outDoc.CreateElement("AccessLicenseNumber");
                XmlText txt = outDoc.CreateTextNode(Globals.upsLicenseNum);
                accessLicenseNumber.AppendChild(txt);
                root.AppendChild(accessLicenseNumber);

                XmlElement userId = outDoc.CreateElement("UserId");
                txt = outDoc.CreateTextNode(Globals.upsUserID);
                userId.AppendChild(txt);
                root.AppendChild(userId);

                XmlElement password = outDoc.CreateElement("Password");
                txt = outDoc.CreateTextNode(Globals.upsPassword);
                password.AppendChild(txt);
                root.AppendChild(password);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Globals.errorLog("AR-01", "getAccessRequest", e.ToString());
            }

            return outDoc;
        }
Example #6
0
 private void button3_Click(object sender, EventArgs e)
 {
     XmlDocument doc = new XmlDocument();
     XmlNode root=doc.AppendChild(doc.CreateElement("orion_text"));
     XmlNode prog = root.AppendChild(doc.CreateElement("main"));
     foreach (MainDat.StringBlock blk in main.strings)
     {
         XmlNode bl = prog.AppendChild(doc.CreateElement("block"));
         bl.Attributes.Append(doc.CreateAttribute("id")).Value = blk.id.ToString();
         foreach (OProg.OString s in blk.strings)
         {
             XmlNode st = bl.AppendChild(doc.CreateElement("string"));
             st.Attributes.Append(doc.CreateAttribute("id")).Value = s.id.ToString();
             st.Attributes.Append(doc.CreateAttribute("orig")).Value = s.data;
             st.AppendChild(doc.CreateTextNode(s.data));
         }
     }
     prog = root.AppendChild(doc.CreateElement("prog"));
     int id=0;
     foreach (OProg p in progs.progs)
     {
         XmlNode pr = prog.AppendChild(doc.CreateElement("prog"));
         pr.Attributes.Append(doc.CreateAttribute("id")).Value = id.ToString();
         foreach (OProg.OString s in p.strings)
         {
             XmlNode st = pr.AppendChild(doc.CreateElement("string"));
             st.Attributes.Append(doc.CreateAttribute("id")).Value = s.id.ToString();
             st.Attributes.Append(doc.CreateAttribute("orig")).Value = s.data;
             st.AppendChild(doc.CreateTextNode(s.data));
         }
         id++;
     }
     doc.Save(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),"orion_dc.xml"));
 }
        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));
        }
        public XmlDocument getQuantumViewRequest()
        {
            XmlDocument outDoc = new XmlDocument();
            XmlDeclaration xmlDec = outDoc.CreateXmlDeclaration("1.0", "utf-8", null);

            try
            {
                XmlElement root = outDoc.CreateElement("QuantumViewRequest");
                root.SetAttribute("xml:lang", "en-US");
                outDoc.AppendChild(root);

                XmlElement request = outDoc.CreateElement("Request");
                XmlElement requestAction = outDoc.CreateElement("RequestAction");
                XmlText txt = outDoc.CreateTextNode(Globals.upsRequestAction);
                requestAction.AppendChild(txt);
                request.AppendChild(requestAction);
                root.AppendChild(request);

                XmlElement subRequest = outDoc.CreateElement("SubscriptionRequest");
                XmlElement subName = outDoc.CreateElement("Name");
                txt = outDoc.CreateTextNode(Globals.upsSubscriptionRequest);
                subName.AppendChild(txt);
                subRequest.AppendChild(subName);
                root.AppendChild(subRequest);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Globals.errorLog("QVR-01", "getQuantumViewRequest", e.ToString());
            }

            return outDoc;
        }
        /// <summary>
        ///  TODO: Create new XmlSchema instead of DeepCopy
        /// </summary>
        /// <param name="templateSchema">Arbitrary maindoc schema used as a template for our new base class schema</param>
        /// <param name="sharedElementCount">Number of elements that shoud be copied over to the new base class schema complex type</param>
        /// <returns></returns>
        private static XmlSchema CreateAbstractBaseSchemaFromMaindocSchema(XmlSchema templateSchema, int sharedElementCount)
        {
            XmlSchema abstractBaseSchema = DeepCopy(templateSchema);
            var abstractBaseElement = abstractBaseSchema.Items.OfType<XmlSchemaElement>().Single();          // Single. There can only be one
            var abstractBaseComplexType = abstractBaseSchema.Items.OfType<XmlSchemaComplexType>().Single();  // Christopher Lambert again

            // overwrite template props
            abstractBaseSchema.TargetNamespace = abstractBaseSchema.TargetNamespace.Replace(abstractBaseElement.Name, Constants.abstractBaseSchemaName);
            abstractBaseSchema.Namespaces.Add("", abstractBaseSchema.TargetNamespace);
            abstractBaseSchema.SourceUri = templateSchema.SourceUri.Replace(abstractBaseElement.Name, Constants.abstractBaseSchemaName);

            abstractBaseComplexType.IsAbstract = true;
            abstractBaseComplexType.Annotation.Items.Clear();
            XmlSchemaDocumentation doc = new XmlSchemaDocumentation();
            var nodeCreaterDoc = new XmlDocument();
            doc.Markup = new XmlNode[] { nodeCreaterDoc.CreateTextNode("This is a custom generated class that holds all the props/fields common to all UBL maindocs."),
                                         nodeCreaterDoc.CreateTextNode("You won't find a matching xsd file where it originates from.") };
            abstractBaseComplexType.Annotation.Items.Add(doc);
            abstractBaseComplexType.Name = Constants.abstractBaseSchemaComplexTypeName;

            // remove non-shared tailing elements.
            XmlSchemaObjectCollection elementCollection = (abstractBaseComplexType.Particle as XmlSchemaSequence).Items;
            while (sharedElementCount < elementCollection.Count) elementCollection.RemoveAt(sharedElementCount);

            abstractBaseElement.Name = Constants.abstarctBaseSchemaElementName;
            abstractBaseElement.SchemaTypeName = new XmlQualifiedName(Constants.abstractBaseSchemaComplexTypeName, abstractBaseSchema.TargetNamespace);

            // Don't need schemaLocation for loaded schemas. Will generate schemasetcompile warnings if not removed
            foreach (var baseSchemaImports in abstractBaseSchema.Includes.OfType<XmlSchemaImport>()) baseSchemaImports.SchemaLocation = null;

            return abstractBaseSchema;
        }
        private static XmlElement CreateHistogramElemnt(XmlDocument xmlDoc)
        {
            XmlElement elem = xmlDoc.CreateElement("histogram");
            {
                var hist = xmlDoc.CreateElement("hist");
                {
                    var place = xmlDoc.CreateElement("place");
                    {
                        var text = xmlDoc.CreateTextNode("one");
                        place.AppendChild(text);
                    }

                    var value = xmlDoc.CreateElement("value");
                    {
                        var text = xmlDoc.CreateTextNode("0");
                        value.AppendChild(text);
                    }

                    var height = xmlDoc.CreateElement("height");
                    {
                        var text = xmlDoc.CreateTextNode("0.00px");
                        height.AppendChild(text);
                    }
                    hist.AppendChild(place);
                    hist.AppendChild(value);
                    hist.AppendChild(height);
                }
                elem.AppendChild(hist);
            }
            return elem;
        }
Example #11
0
        private void buttonCreateNode_Click(object sender, RoutedEventArgs e)
        {
            // Load the XML document.
              XmlDocument document = new XmlDocument();
              document.Load(@"C:\Beginning Visual C# 2012\Chapter 22\Books.xml");

              // Get the root element.
              XmlElement root = document.DocumentElement;

              // Create the new nodes.
              XmlElement newBook = document.CreateElement("book");
              XmlElement newTitle = document.CreateElement("title");
              XmlElement newAuthor = document.CreateElement("author");
              XmlElement newCode = document.CreateElement("code");
              XmlText title = document.CreateTextNode("Beginning Visual C# 2010");
              XmlText author = document.CreateTextNode("Karli Watson et al");
              XmlText code = document.CreateTextNode("1234567890");
              XmlComment comment = document.CreateComment("The previous edition");

              // Insert the elements.
              newBook.AppendChild(comment);
              newBook.AppendChild(newTitle);
              newBook.AppendChild(newAuthor);
              newBook.AppendChild(newCode);
              newTitle.AppendChild(title);
              newAuthor.AppendChild(author);
              newCode.AppendChild(code);
              root.InsertAfter(newBook, root.FirstChild);

              document.Save(@"C:\Beginning Visual C# 2012\Chapter 22\Books.xml");
        }
Example #12
0
        public static void SaveToFile(string filename, List<Preset> presets)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                XmlElement root = doc.CreateElement("presets");
                doc.AppendChild(root);
                foreach (Preset bmi in presets)
                {
                    XmlElement bm = doc.CreateElement("preset");
                    root.AppendChild(bm);

                    XmlElement el = doc.CreateElement("Name");
                    XmlText txt = doc.CreateTextNode(bmi.Name);
                    el.AppendChild(txt);
                    bm.AppendChild(el);

                    el = doc.CreateElement("VisibleColumns");
                    txt = doc.CreateTextNode(bmi.VisibleColumns);
                    el.AppendChild(txt);
                    bm.AppendChild(el);

                    el = doc.CreateElement("ColumnOrder");
                    txt = doc.CreateTextNode(bmi.ColumnOrder);
                    el.AppendChild(txt);
                    bm.AppendChild(el);
                }
                doc.Save(filename);
            }
            catch
            {
            }
        }
Example #13
0
        static void BuildPage(IPage page, XmlNode parent, XmlDocument doc)
        {
            XmlNode pagenode = doc.CreateElement("page");
            parent.AppendChild(pagenode);

            XmlNode titlenode = doc.CreateElement("title");
            titlenode.AppendChild(doc.CreateTextNode(page.Title));
            pagenode.AppendChild(titlenode);

            XmlNode textnode = doc.CreateElement("text");
            textnode.AppendChild(doc.CreateTextNode(page.Text));
            pagenode.AppendChild(textnode);

            XmlNode iconnode = doc.CreateElement("icon");
            iconnode.AppendChild(doc.CreateTextNode(page.Icon));
            pagenode.AppendChild(iconnode);

            XmlNode rendermodenode = doc.CreateElement("rendermode");
            rendermodenode.AppendChild(doc.CreateTextNode(page.RenderMode));
            pagenode.AppendChild(rendermodenode);

            XmlNode itemsnode = doc.CreateElement("items");
            pagenode.AppendChild(itemsnode);

            for (int j = 0; j < page.Items.Count; j++)
                BuildIItem(page, doc, itemsnode, page.Items[j], "item");

            XmlNode actionsnode = doc.CreateElement("actions");
            pagenode.AppendChild(actionsnode);

            for (int j = 0; j < page.Actions.Count; j++)
                BuildIItem(page, doc, actionsnode, page.Actions[j], "action");
        }
Example #14
0
        //Add a node
        private void button1_Click(object sender, EventArgs e)
        {
            //Load the XML document
            XmlDocument document = new XmlDocument();
            document.Load("../../Books.xml");

            //Get the root element
            XmlElement root = document.DocumentElement;


            //Create the new nodes
            XmlElement newBook = document.CreateElement("book");
            XmlElement newTitle = document.CreateElement("title");
            XmlElement newAuthor = document.CreateElement("author");
            XmlElement newCode = document.CreateElement("code");
            XmlText title = document.CreateTextNode("Beginning Visual C# 3rd Edition");  
            XmlText author = document.CreateTextNode("Karli Watson C# 3rd Edition");
            XmlText code = document.CreateTextNode("1234567890");
            XmlComment comment = document.CreateComment("This book is the book you are reading");

            //Insert the elements
            newBook.AppendChild(comment);
            newBook.AppendChild(newTitle);
            newBook.AppendChild(newAuthor);
            newBook.AppendChild(newCode);
            newTitle.AppendChild(title);
            newAuthor.AppendChild(author);
            newCode.AppendChild(code);
            root.InsertAfter(newBook, root.LastChild);

            document.Save("../../Books.xml");

            listBoxXmlNodes.Items.Clear();
            RecurseXmlDocument((XmlNode)document.DocumentElement, 0);  
        }
Example #15
0
        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            //putanja do xml file-a
            string path = System.IO.Path.Combine(Environment.CurrentDirectory, @"..\..\Students.xml");
            //ucitavanje xml file-a
            xml = new XmlDocument();
            xml.Load(path);
            //dodavanje novog elementa
            XmlElement root = xml.DocumentElement;
            XmlElement elem = xml.CreateElement("Student");
            root.AppendChild(elem);

            elem = xml.CreateElement("JMBAG");
            XmlText text4 = xml.CreateTextNode(jmbagTextBox.Text);
            root.LastChild.AppendChild(elem);
            root.LastChild.LastChild.AppendChild(text4);

            elem = xml.CreateElement("Ime");
            XmlText text = xml.CreateTextNode(nameTextBox.Text);
            root.LastChild.AppendChild(elem);
            root.LastChild.LastChild.AppendChild(text);

            elem = xml.CreateElement("Prezime");
            XmlText text1 = xml.CreateTextNode(lastnameTextBox.Text);
            root.LastChild.AppendChild(elem);
            root.LastChild.LastChild.AppendChild(text1);

            elem = xml.CreateElement("Godina");
            XmlText text2 = xml.CreateTextNode(yearTextBox.Text);
            root.LastChild.AppendChild(elem);
            root.LastChild.LastChild.AppendChild(text2);

            elem = xml.CreateElement("Smjer");
            XmlText text3 = xml.CreateTextNode(smjerTextBox.Text);
            root.LastChild.AppendChild(elem);
            root.LastChild.LastChild.AppendChild(text3);

            xml.Save(path);

            //dio koda koji se odnosi na messagebox koji se pojavi nakon klika na button "Spremi"
            string caption = "Spremljeno";
            string question = "Zelite li dodati jos zapisa?";
            if (MessageBox.Show(question, caption, MessageBoxButton.YesNo) == MessageBoxResult.No)
            {
                this.Close();
            }

            else
            {
                nameTextBox.Clear();
                lastnameTextBox.Clear();
                yearTextBox.Clear();
                smjerTextBox.Clear();
                jmbagTextBox.Clear();
            }
            
            

        }
Example #16
0
        /// <summary>
        /// 保存心理预测的结果
        /// </summary> 
        /// <param name="strFileName"></param>
        public static void SaveEmotionPredictionsHistory(string strFileName)
        {
            XmlDocument xmlDoc = new XmlDocument();

            XmlNode xmlNode = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
            xmlDoc.AppendChild(xmlNode);

            XmlNode xmlRoot = xmlDoc.CreateElement("Predictions");
            xmlDoc.AppendChild(xmlRoot);
            foreach (KeyValuePair<long, double> item in dic_SOM_Predictions)
            {
                XmlNode node = xmlDoc.CreateElement("Record");
                XmlAttribute timeNode = xmlDoc.CreateAttribute("Time");
                timeNode.Value = item.Key.ToString();
                node.Attributes.Append(timeNode);

                XmlNode SOMNode = xmlDoc.CreateElement("SOM");
                SOMNode.AppendChild(xmlDoc.CreateTextNode(dic_SOM_Predictions[item.Key].ToString()));

                XmlNode DEPNode = xmlDoc.CreateElement("DEP");
                DEPNode.AppendChild(xmlDoc.CreateTextNode(dic_DEP_Predictions[item.Key].ToString()));

                XmlNode AMXNode = xmlDoc.CreateElement("ANX");
                AMXNode.AppendChild(xmlDoc.CreateTextNode(dic_ANX_Predictions[item.Key].ToString()));

                XmlNode PSDNode = xmlDoc.CreateElement("PSD");
                PSDNode.AppendChild(xmlDoc.CreateTextNode(dic_PSD_Predictions[item.Key].ToString()));

                XmlNode HYPNode = xmlDoc.CreateElement("HYP");
                HYPNode.AppendChild(xmlDoc.CreateTextNode(dic_HYP_Predictions[item.Key].ToString()));

                XmlNode UNRNode = xmlDoc.CreateElement("UNR");
                UNRNode.AppendChild(xmlDoc.CreateTextNode(dic_UNR_Predictions[item.Key].ToString()));

                XmlNode HMANode = xmlDoc.CreateElement("HMA");
                HMANode.AppendChild(xmlDoc.CreateTextNode(dic_HMA_Predictions[item.Key].ToString()));

                node.AppendChild(SOMNode);
                node.AppendChild(DEPNode);
                node.AppendChild(AMXNode);
                node.AppendChild(PSDNode);
                node.AppendChild(HYPNode);
                node.AppendChild(UNRNode);
                node.AppendChild(HMANode);
                xmlRoot.AppendChild(node);
            }
            try
            {
                if (System.IO.File.Exists(strFileName))
                {
                    System.IO.File.Delete(strFileName);
                }
                xmlDoc.Save(strFileName);
            }
            catch (System.Exception e)
            {
                return;
            }
        }
Example #17
0
        /// <summary>
        /// Performs a remote request to the license server to get a list of license and signature pairs
        /// </summary>
        /// <param name="domainFeatures"></param>
        /// <returns></returns>
        public List<KeyValuePair<string, string>> RequestLicenses(Uri licensingUrl, Guid appId, Dictionary<string, List<Guid>> domainFeatures)
        {
            var results = new List<KeyValuePair<string,string>>();

            XmlDocument doc = new XmlDocument();
            var root = doc.CreateElement("licenseRequest");
            doc.AppendChild(root);
            var appIdElement = doc.CreateElement("appId");
            appIdElement.AppendChild(doc.CreateTextNode(appId.ToString()));
            root.AppendChild(appIdElement);
            var domains = doc.CreateElement("domains");
            root.AppendChild(domains);
            foreach (string domain in domainFeatures.Keys)
            {
                var d = doc.CreateElement("domain");
                d.SetAttribute("name", domain);
                foreach (Guid g in domainFeatures[domain])
                {
                    var feature = doc.CreateElement("feature");
                    feature.AppendChild(doc.CreateTextNode(g.ToString()));
                    d.AppendChild(feature);
                }
                domains.AppendChild(d);
            }
            var request = (System.Net.HttpWebRequest)WebRequest.Create((Uri) licensingUrl);
            request.ContentType = "application/xml; charset=utf-8";
            request.Method = "POST";
            byte[] body = UTF8Encoding.UTF8.GetBytes(doc.OuterXml);
            request.ContentLength = body.Length;
            using (var upstream = request.GetRequestStream())
            {
                upstream.Write(body, 0, body.Length);
            }
            using (var response = request.GetResponse())
            {
                XmlDocument rdoc = new XmlDocument();
                rdoc.Load(response.GetResponseStream());
                foreach (var l in rdoc.DocumentElement.ChildNodes)
                {
                    var lic = l as XmlElement;
                    if (lic != null && lic.Name == "license")
                    {
                        var signatures = lic.GetElementsByTagName("signature");
                        if (signatures.Count != 1)
                            continue;

                        var values = lic.GetElementsByTagName("value");
                        if (values.Count != 1)
                            continue;

                        results.Add(new KeyValuePair<string, string>(
                            values[0].InnerText,
                            signatures[0].InnerText));
                    }
                }
            }
            return results;
        }
Example #18
0
        static void BuildPageTo(IPage page, XmlNode parent, XmlDocument doc)
        {
            XmlNode pagenode = doc.CreateElement("page");
            parent.AppendChild(pagenode);

            XmlNode titlenode = doc.CreateElement("title");
            titlenode.InnerText = page.Title;
            pagenode.AppendChild(titlenode);

            XmlNode textnode = doc.CreateElement("text");
            titlenode.InnerText = page.Text;
            pagenode.AppendChild(textnode);

            XmlNode iconnode = doc.CreateElement("icon");
            titlenode.InnerText = page.Icon;
            pagenode.AppendChild(iconnode);

            XmlNode rendermodenode = doc.CreateElement("rendermode");
            rendermodenode.InnerText = page.RenderMode;
            pagenode.AppendChild(rendermodenode);

            XmlNode itemsnode = doc.CreateElement("items");
            pagenode.AppendChild(itemsnode);

            for (int j = 0; j < page.Items.Count; j++)
            {
                XmlNode itemnode = doc.CreateElement("item");
                itemsnode.AppendChild(titlenode);

                XmlAttribute commandattribute = doc.CreateAttribute("command");
                commandattribute.Value = page.Items[j].Command;
                itemnode.Attributes.Append(commandattribute);

                XmlText textnode2 = doc.CreateTextNode(page.Items[j].Text);
                itemnode.AppendChild(textnode2);

            }

            XmlNode actionsnode = doc.CreateElement("actions");
            pagenode.AppendChild(actionsnode);

            for (int j = 0; j < page.Actions.Count; j++)
            {
                XmlNode itemnode = doc.CreateElement("item");
                itemsnode.AppendChild(titlenode);

                XmlAttribute commandattribute = doc.CreateAttribute("command");
                commandattribute.Value = page.Actions[j].Command;
                itemnode.Attributes.Append(commandattribute);

                XmlAttribute iconattribute = doc.CreateAttribute("command");
                iconattribute.Value = page.Actions[j].Icon;
                itemnode.Attributes.Append(iconattribute);

                XmlText textnode2 = doc.CreateTextNode(page.Actions[j].Text);
                itemnode.AppendChild(textnode2);
            }
        }
Example #19
0
        public void ProcessRequest(HttpContext context)
        {
            // build xml 
            XmlDocument xmlDoc = new XmlDocument();
            // XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", null, null);
            // xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
            
            XmlElement rootNode = xmlDoc.CreateElement("opml");
            rootNode.SetAttribute("version", "1.1");
            xmlDoc.AppendChild(rootNode);

            XmlElement parentNode = xmlDoc.CreateElement("head");

            XmlElement titleNode = xmlDoc.CreateElement("title");
            XmlElement ownerNameNode = xmlDoc.CreateElement("ownerName");
            XmlElement ownerEmailNode = xmlDoc.CreateElement("ownerEmail");

            XmlText titleText = xmlDoc.CreateTextNode("mySubscriptions.opml");
            XmlText ownerNameText = xmlDoc.CreateTextNode("Dave Winer");
            XmlText ownerEmailText = xmlDoc.CreateTextNode("*****@*****.**");

            xmlDoc.DocumentElement.PrependChild(parentNode);

            parentNode.AppendChild(titleNode);
            parentNode.AppendChild(ownerNameNode);
            parentNode.AppendChild(ownerEmailNode);

            titleNode.AppendChild(titleText);
            ownerNameNode.AppendChild(ownerNameText);
            ownerEmailNode.AppendChild(ownerEmailText);

            XmlElement parent2Node = xmlDoc.CreateElement("body");

            foreach (RssFeedInfo rss in RssFeedInfo.GetRssFeedInfos())
            {
                XmlElement outlineNode = xmlDoc.CreateElement("outline");

                outlineNode.SetAttribute("text", rss.FeedTitle);
                outlineNode.SetAttribute("description", rss.FeedDescription);
                outlineNode.SetAttribute("htmlUrl", rss.HtmlUrl);
                outlineNode.SetAttribute("title", rss.FeedTitle);
                outlineNode.SetAttribute("version", "");
                outlineNode.SetAttribute("xmlUrl", rss.XmlUrl);

                parent2Node.AppendChild(outlineNode);
            }

            xmlDoc.DocumentElement.InsertAfter(parent2Node, parentNode);

            // add xml to resposne stream
            context.Response.Write(xmlDoc.OuterXml.ToString());
            context.Response.End();
            
            // set mime type
            context.Response.ContentType = "text/x-opml";
        }
Example #20
0
 /// <summary>
 /// Save Dynamic GDALImageStores on Exit
 /// </summary>
 /// <param name="worldDoc">Create Relevant ImageAccessor Node</param>
 /// <returns></returns>
 public override System.Xml.XmlNode ToXml(System.Xml.XmlDocument worldDoc)
 {
     System.Xml.XmlNode baseNode        = base.ToXml(worldDoc);
     System.Xml.XmlNode sourceFileNode  = worldDoc.CreateElement("GDALFileName");
     System.Xml.XmlNode datasetnameNode = worldDoc.CreateElement("DatasetName");
     sourceFileNode.AppendChild(worldDoc.CreateTextNode(this.m_sourcefilename));
     datasetnameNode.AppendChild(worldDoc.CreateTextNode(this.m_dataSetName));
     baseNode.AppendChild(sourceFileNode);
     baseNode.AppendChild(datasetnameNode);
     return(baseNode);
 }
        internal void GenerateGuestbookEntry(string userName, string userMessage)
        {
            // Load the xml file

            var xmldoc = new XmlDocument();

            xmldoc.Load( Server.MapPath("guestbook.xml"));

            //Create a new guest element and add it to the root node

            XmlElement parentNode = xmldoc.CreateElement("guest");

            if (xmldoc.DocumentElement != null)
                xmldoc.DocumentElement.PrependChild(parentNode);

            // Create the required nodes

            XmlElement nameNode = xmldoc.CreateElement("name");

            XmlElement messageNode = xmldoc.CreateElement("message");

            XmlElement dateNode = xmldoc.CreateElement("date");

            // retrieve the text

            XmlText userNameText = xmldoc.CreateTextNode(userName);

            XmlText userMessageText = xmldoc.CreateTextNode(userMessage);

            XmlText messageDateText
                = xmldoc.CreateTextNode
                (DateTime.Now.ToString
                (CultureInfo.InvariantCulture));

            // append the nodes to the parentNode without the value

            parentNode.AppendChild(nameNode);

            parentNode.AppendChild(messageNode);

            parentNode.AppendChild(dateNode);

            // save the value of the fields into the nodes

            nameNode.AppendChild(userNameText);

            messageNode.AppendChild(userMessageText);

            dateNode.AppendChild(messageDateText);

            // Save to the XML file

            xmldoc.Save(Server.MapPath("guestbook.xml"));
        }
Example #22
0
    static int ConnectSample()
    {
        PmsXchangeService service = new PmsXchangeService();

        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
        //The security header is untyped due to the lax processing instruction
        System.Xml.XmlElement token    = doc.CreateElement("UsernameToken");
        System.Xml.XmlElement password = doc.CreateElement("Password");
        System.Xml.XmlElement username = doc.CreateElement("Username");

        System.Xml.XmlText usernameText = doc.CreateTextNode("SPIOrangeTest");
        System.Xml.XmlText passwordText = doc.CreateTextNode("YOURPASSWORD");
        username.AppendChild(usernameText);
        password.AppendChild(passwordText);
        token.AppendChild(username);
        token.AppendChild(password);

        System.Xml.XmlElement[] elements = new System.Xml.XmlElement[] { token };

        SecurityHeaderType type = new SecurityHeaderType();

        service.Security     = type;
        service.Security.Any = elements;

        OTA_ReadRQ otaReadRQ = new OTA_ReadRQ();

        otaReadRQ.Version = 1.0M;
        OTA_ReadRQReadRequests rr = new OTA_ReadRQReadRequests();
        OTA_ReadRQReadRequestsHotelReadRequest hotelR = new OTA_ReadRQReadRequestsHotelReadRequest();

        hotelR.HotelCode = "123";

        object[] ob = new object[] { hotelR };
        rr.Items = ob;

        OTA_ReadRQReadRequestsHotelReadRequestSelectionCriteria crit = new OTA_ReadRQReadRequestsHotelReadRequestSelectionCriteria();
        OTA_ReadRQReadRequestsHotelReadRequestSelectionCriteriaSelectionType selType = OTA_ReadRQReadRequestsHotelReadRequestSelectionCriteriaSelectionType.Undelivered;

        crit.SelectionType          = selType;
        crit.SelectionTypeSpecified = true;

        hotelR.SelectionCriteria = crit;
        otaReadRQ.ReadRequests   = rr;
        // Retrieve the response
        Console.WriteLine("About to make request :::");
        OTA_ResRetrieveRS resRetrieveRS = service.ReadRQ(otaReadRQ);

        Console.WriteLine("Received response :::");

        //Do further work ....
        // ....
        return(0);
    }
Example #23
0
        public void LogIt(DateTime exceptionDate, string exceptionSource, string exceptionMessage)
        {
            Console.WriteLine(" XML Logger ");

            try
            {
                const string fileName = "appLog.xml";
                var xmlDocument = new XmlDocument();

                try
                {
                    xmlDocument.Load(fileName);
                }
                catch (FileNotFoundException)
                {
                    var xmlWriter = new XmlTextWriter(fileName, System.Text.Encoding.UTF8) { Formatting = Formatting.Indented };
                    xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
                    xmlWriter.WriteStartElement("Logs");
                    xmlWriter.Close();
                    xmlDocument.Load(fileName);
                }

                XmlNode logRoot = xmlDocument.DocumentElement;
                XmlElement logElement = xmlDocument.CreateElement("log");
                XmlElement dateElement = xmlDocument.CreateElement("exceptionDate");
                XmlElement sourceElement = xmlDocument.CreateElement("exceptionSource");
                XmlElement messageElement = xmlDocument.CreateElement("exceptionMessage");

                XmlText dateText = xmlDocument.CreateTextNode("date");
                dateText.Value = exceptionDate.ToString();
                XmlText sourceText = xmlDocument.CreateTextNode("source");
                sourceText.Value = exceptionSource;
                XmlText messageText = xmlDocument.CreateTextNode("message");
                messageText.Value = exceptionMessage;

                logRoot.AppendChild(logElement);

                dateElement.AppendChild(dateText);
                sourceElement.AppendChild(sourceText);
                messageElement.AppendChild(messageText);

                logElement.AppendChild(dateElement);
                logElement.AppendChild(sourceElement);
                logElement.AppendChild(messageElement);

                xmlDocument.Save(fileName);
            }
            catch (Exception)
            {
                Console.WriteLine(" Ya mejor lo escribo en pantalla ");
            }
        }
Example #24
0
        // Mapping an business object for an order to an XmlDocument for an invoice
        public static XmlDocument OoOrder2XmlInvoice(OO.Order o)
        {
            string ns = "http://www.vertical.com/Invoice";
            var doc = new XmlDocument();

            var inv = doc.CreateElement("Invoice", ns);
            doc.AppendChild(inv);

            var name = doc.CreateElement("Name", ns);
            inv.AppendChild(name);
            name.AppendChild(doc.CreateTextNode(o.Cust.Name));

            // Ditto for street, city, zip, state

            var street = doc.CreateElement("Street", ns);
            inv.AppendChild(street);
            street.AppendChild(doc.CreateTextNode(o.Cust.Addr.Street));

            var city = doc.CreateElement("City", ns);
            inv.AppendChild(city);
            city.AppendChild(doc.CreateTextNode(o.Cust.Addr.City));

            var zip = doc.CreateElement("Zip", ns);
            inv.AppendChild(zip);
            zip.AppendChild(doc.CreateTextNode(o.Cust.Addr.Zip));

            var state = doc.CreateElement("State", ns);
            inv.AppendChild(state);
            state.AppendChild(doc.CreateTextNode(o.Cust.Addr.State));

            foreach (var i in o.Items)
            {
                var item = doc.CreateElement("Position", ns);
                inv.AppendChild(item);

                var prodid = doc.CreateElement("ProdId", ns);
                item.AppendChild(prodid);
                prodid.AppendChild(doc.CreateTextNode(i.Prod.Id));

                // Ditto for price, quantity

                var price = doc.CreateElement("Price", ns);
                item.AppendChild(price);
                price.AppendChild(doc.CreateTextNode(XmlConvert.ToString(i.Price)));

                var quantity = doc.CreateElement("Quantity", ns);
                item.AppendChild(quantity);
                quantity.AppendChild(doc.CreateTextNode(i.Quantity.ToString()));
            }

            var total = doc.CreateElement("Total", ns);
            inv.AppendChild(total);
            total.AppendChild(doc.CreateTextNode(o.Total().ToString()));

            return doc;
        }
 internal override XmlElement GetXml(XmlDocument xmlDocument)
 {
     RSAParameters parameters = this.m_key.ExportParameters(false);
     XmlElement element = xmlDocument.CreateElement("KeyValue", "http://www.w3.org/2000/09/xmldsig#");
     XmlElement newChild = xmlDocument.CreateElement("RSAKeyValue", "http://www.w3.org/2000/09/xmldsig#");
     XmlElement element3 = xmlDocument.CreateElement("Modulus", "http://www.w3.org/2000/09/xmldsig#");
     element3.AppendChild(xmlDocument.CreateTextNode(Convert.ToBase64String(parameters.Modulus)));
     newChild.AppendChild(element3);
     XmlElement element4 = xmlDocument.CreateElement("Exponent", "http://www.w3.org/2000/09/xmldsig#");
     element4.AppendChild(xmlDocument.CreateTextNode(Convert.ToBase64String(parameters.Exponent)));
     newChild.AppendChild(element4);
     element.AppendChild(newChild);
     return element;
 }
Example #26
0
        private void btnAddCourse_Click(object sender, EventArgs e)
        {
            //Load xml document
            XmlDocument document = new XmlDocument();
            document.Load("../../Courseinfo.xml");

            //Get the root element
            XmlElement root = document.DocumentElement;

            string cno = textBoxCNO.Text.ToString().Trim();
            string cname = textBoxCNAME.Text.ToString().Trim();
            string cprise = textBoxCP.Text.ToString().Trim();
            string ctno = textBoxCTNO.Text.ToString().Trim();
            string ctname = textBoxCTNAME.Text.ToString().Trim();

            XmlElement newCourse = document.CreateElement("course");
            XmlElement newCno = document.CreateElement("cno");
            XmlElement newCname = document.CreateElement("cname");
            XmlElement newCprise = document.CreateElement("cprise");
            XmlElement newCtno = document.CreateElement("ctno");
            XmlElement newCtname = document.CreateElement("ctname");

            XmlText cnotext = document.CreateTextNode(cno);
            XmlText cnametext = document.CreateTextNode(cname);
            XmlText cprisetext = document.CreateTextNode(cprise);
            XmlText ctnotext = document.CreateTextNode(ctno);
            XmlText ctnametext = document.CreateTextNode(ctname);

            newCourse.AppendChild(newCno);
            newCourse.AppendChild(newCname);
            newCourse.AppendChild(newCprise);
            newCourse.AppendChild(newCtno);
            newCourse.AppendChild(newCtname);

            newCno.AppendChild(cnotext);
            newCname.AppendChild(cnametext);
            newCprise.AppendChild(cprisetext);
            newCtno.AppendChild(ctnotext);
            newCtname.AppendChild(ctnametext);

            root.InsertAfter(newCourse, root.LastChild);
            document.Save("../../Courseinfo.xml");

            textBoxCNO.Text = null;
            textBoxCNAME.Text = null;
            textBoxCP.Text = null;
            textBoxCTNO.Text = null;
            textBoxCTNAME.Text = null;
 
        }
Example #27
0
        private string WrapInSoapMessage(string stsResponse, string relyingPartyIdentifier)
        {
            XmlDocument samlAssertion = new XmlDocument();
            samlAssertion.PreserveWhitespace = true;
            samlAssertion.LoadXml(stsResponse);

            //Select the book node with the matching attribute value.
            String notBefore = samlAssertion.DocumentElement.FirstChild.Attributes["NotBefore"].Value;
            String notOnOrAfter = samlAssertion.DocumentElement.FirstChild.Attributes["NotOnOrAfter"].Value;

            XmlDocument soapMessage = new XmlDocument();
            XmlElement soapEnvelope = soapMessage.CreateElement("t", "RequestSecurityTokenResponse", "http://schemas.xmlsoap.org/ws/2005/02/trust");
            soapMessage.AppendChild(soapEnvelope);
            XmlElement lifeTime = soapMessage.CreateElement("t", "Lifetime", soapMessage.DocumentElement.NamespaceURI);
            soapEnvelope.AppendChild(lifeTime);
            XmlElement created = soapMessage.CreateElement("wsu", "Created", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
            XmlText createdValue = soapMessage.CreateTextNode(notBefore);
            created.AppendChild(createdValue);
            lifeTime.AppendChild(created);
            XmlElement expires = soapMessage.CreateElement("wsu", "Expires", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
            XmlText expiresValue = soapMessage.CreateTextNode(notOnOrAfter);
            expires.AppendChild(expiresValue);
            lifeTime.AppendChild(expires);
            XmlElement appliesTo = soapMessage.CreateElement("wsp", "AppliesTo", "http://schemas.xmlsoap.org/ws/2004/09/policy");
            soapEnvelope.AppendChild(appliesTo);
            XmlElement endPointReference = soapMessage.CreateElement("wsa", "EndpointReference", "http://www.w3.org/2005/08/addressing");
            appliesTo.AppendChild(endPointReference);
            XmlElement address = soapMessage.CreateElement("wsa", "Address", endPointReference.NamespaceURI);
            XmlText addressValue = soapMessage.CreateTextNode(relyingPartyIdentifier);
            address.AppendChild(addressValue);
            endPointReference.AppendChild(address);
            XmlElement requestedSecurityToken = soapMessage.CreateElement("t", "RequestedSecurityToken", soapMessage.DocumentElement.NamespaceURI);
            XmlNode samlToken = soapMessage.ImportNode(samlAssertion.DocumentElement, true);
            requestedSecurityToken.AppendChild(samlToken);
            soapEnvelope.AppendChild(requestedSecurityToken);
            XmlElement tokenType = soapMessage.CreateElement("t", "TokenType", soapMessage.DocumentElement.NamespaceURI);
            XmlText tokenTypeValue = soapMessage.CreateTextNode("urn:oasis:names:tc:SAML:1.0:assertion");
            tokenType.AppendChild(tokenTypeValue);
            soapEnvelope.AppendChild(tokenType);
            XmlElement requestType = soapMessage.CreateElement("t", "RequestType", soapMessage.DocumentElement.NamespaceURI);
            XmlText requestTypeValue = soapMessage.CreateTextNode("http://schemas.xmlsoap.org/ws/2005/02/trust/Issue");
            requestType.AppendChild(requestTypeValue);
            soapEnvelope.AppendChild(requestType);
            XmlElement keyType = soapMessage.CreateElement("t", "KeyType", soapMessage.DocumentElement.NamespaceURI);
            XmlText keyTypeValue = soapMessage.CreateTextNode("http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey");
            keyType.AppendChild(keyTypeValue);
            soapEnvelope.AppendChild(keyType);

            return soapMessage.OuterXml;
        }
Example #28
0
        protected void adminSaveBtn_Click(object sender, EventArgs e)
        {
            //XML Data Source : AdminPost.xml
            XmlDocument xmldoc = XmlDataSource1.GetXmlDocument();
            //Get the XML Data Latest Post Record
            XmlNodeList xnlist = xmldoc.SelectNodes("//user[last()]");

            //Get the Latest Record ID
            String olduserID = xnlist[0].Attributes[0].Value.ToString();
            int    user      = int.Parse(olduserID.Substring(1));

            user++;
            String newUserID = "U" + user;

            XmlDocument doc = new System.Xml.XmlDocument();

            doc.Load(Server.MapPath(AdminXmlFilePath));

            XmlNode      adminNode      = doc.CreateElement("user");
            XmlAttribute adminAttribute = doc.CreateAttribute("id");

            adminAttribute.Value = newUserID;
            adminNode.Attributes.Append(adminAttribute);
            doc.DocumentElement.AppendChild(adminNode);

            XmlNode emailNode = doc.CreateElement("email");

            emailNode.AppendChild(doc.CreateTextNode(this.adminEmail.Text));
            adminNode.AppendChild(emailNode);


            XmlNode passNode = doc.CreateElement("pass");

            passNode.AppendChild(doc.CreateTextNode(this.adminPassword.Text));
            adminNode.AppendChild(passNode);

            XmlNode nameNode = doc.CreateElement("name");

            nameNode.AppendChild(doc.CreateTextNode(this.adminName.Text));
            adminNode.AppendChild(nameNode);

            XmlNode numberNode = doc.CreateElement("numberPost");

            numberNode.AppendChild(doc.CreateTextNode("0"));
            adminNode.AppendChild(numberNode);

            doc.Save(Server.MapPath(AdminXmlFilePath));
            Response.Redirect("AdminSignIn.aspx");
        }
Example #29
0
 public void PrintToXML()
 {
     XmlDocument xmlDoc = new XmlDocument();
     XmlElement xmlRoot = xmlDoc.CreateElement("ICCProfile");
     XmlElement[] xmlList = { xmlDoc.CreateElement("Type"), xmlDoc.CreateElement("Number_of_components"), xmlDoc.CreateElement("Description") };
     xmlList[0].AppendChild(xmlDoc.CreateTextNode(iccProfile.ClrType.ToString()));
     xmlList[1].AppendChild(xmlDoc.CreateTextNode(iccProfile.NumComponents));
     xmlList[2].AppendChild(xmlDoc.CreateTextNode(iccProfile.Description));
     foreach (XmlElement xe in xmlList)
     {
         xmlRoot.AppendChild(xe);
     }
     xmlDoc.AppendChild(xmlRoot);
     xmlDoc.Save("out.xml");
 }
Example #30
0
 /// <summary>
 /// Create a property element.  Do not append it though!
 /// </summary>
 /// <param name="doc">The document to use.</param>
 /// <param name="name">The name of the property.</param>
 /// <param name="value_ren">The value to add to the property.</param>
 /// <returns>The newly created property.</returns>
 public static XmlNode CreateProperty(XmlDocument doc, String name,
          String value_ren)
 {
     XmlNode n = doc.CreateElement(name);
     n.AppendChild(doc.CreateTextNode(value));
     return n;
 }
 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);
 }
 private XmlElement CreateElement(XmlDocument xDoc, string name, string value)
 {
     XmlElement xnode = xDoc.CreateElement(name);
     XmlText xtext = xDoc.CreateTextNode(value);
     xnode.AppendChild(xtext);
     return xnode;
 }
Example #33
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (textBox1.Text.Equals(textBox2.Text))
     {
         XmlDocument xmldoc = new XmlDocument();
         XmlElement xmlelem;
         XmlNode xmlnode;
         XmlText xmltext;
         xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
         xmldoc.AppendChild(xmlnode);
         xmlelem = xmldoc.CreateElement("", "ROOT", "");
         xmltext = xmldoc.CreateTextNode(textBox1.Text);
         xmlelem.AppendChild(xmltext);
         xmldoc.AppendChild(xmlelem);
         xmldoc.Save(path + "\\p.xml");
         this.Close();
     }
     else
     {
         MessageBox.Show("Two text do not match", "Error");
         textBox1.Clear();
         textBox2.Clear();
         textBox1.Focus();
     }
 }
Example #34
0
    private XmlNode BuildProductNodes(XmlNode RootNode, ProductInfo ProdInfo)
    {
        //Build the document structure needed to add a new product

        XmlNode NameNode = null;
        //software name
        XmlNode VersionNode = null;
        //software version
        XmlNode VCodeNode = null;
        //software vcode
        XmlNode GCodeNode = null;
        //software gcode

        XmlNode productsNode = null;

        //MyXMLDoc.namespaces
        productsNode = MyXMLDoc.CreateElement("Products");
        RootNode.AppendChild(productsNode);

        //Create all the new data nodes
        NameNode    = MyXMLDoc.CreateElement("name");
        VersionNode = MyXMLDoc.CreateElement("version");
        VCodeNode   = MyXMLDoc.CreateElement("vcode");
        GCodeNode   = MyXMLDoc.CreateElement("gcode");

        //fill info
        NameNode.AppendChild(MyXMLDoc.CreateTextNode(ProdInfo.Name));
        VersionNode.AppendChild(MyXMLDoc.CreateTextNode(ProdInfo.Version));
        VCodeNode.AppendChild(MyXMLDoc.CreateTextNode(ProdInfo.VCode));
        GCodeNode.AppendChild(MyXMLDoc.CreateTextNode(ProdInfo.GCode));

        //Add the new nodes to the root "Products" node
        //Note that the append order is important
        productsNode.AppendChild(NameNode);
        productsNode.AppendChild(VersionNode);
        productsNode.AppendChild(VCodeNode);
        productsNode.AppendChild(GCodeNode);

        //Return the new root "Products" node
        return(RootNode);
    }
        private void ValidateElement()
        {
            nsManager.PushScope();
            XmlElement elementNode = currentNode as XmlElement;

            Debug.Assert(elementNode != null);

            XmlAttributeCollection attributes = elementNode.Attributes;
            XmlAttribute           attr       = null;

            //Find Xsi attributes that need to be processed before validating the element
            string xsiNil  = null;
            string xsiType = null;

            for (int i = 0; i < attributes.Count; i++)
            {
                attr = attributes[i];
                string objectNs   = attr.NamespaceURI;
                string objectName = attr.LocalName;
                Debug.Assert(nameTable.Get(attr.NamespaceURI) != null);
                Debug.Assert(nameTable.Get(attr.LocalName) != null);

                if (Ref.Equal(objectNs, NsXsi))
                {
                    if (Ref.Equal(objectName, XsiType))
                    {
                        xsiType = attr.Value;
                    }
                    else if (Ref.Equal(objectName, XsiNil))
                    {
                        xsiNil = attr.Value;
                    }
                }
                else if (Ref.Equal(objectNs, NsXmlNs))
                {
                    nsManager.AddNamespace(attr.Prefix.Length == 0 ? string.Empty : attr.LocalName, attr.Value);
                }
            }
            validator.ValidateElement(elementNode.LocalName, elementNode.NamespaceURI, schemaInfo, xsiType, xsiNil, null, null);
            ValidateAttributes(elementNode);
            validator.ValidateEndOfAttributes(schemaInfo);

            //If element has children, drill down
            for (XmlNode child = elementNode.FirstChild; child != null; child = child.NextSibling)
            {
                ValidateNode(child);
            }
            //Validate end of element
            currentNode = elementNode; //Reset current Node for validation call back
            validator.ValidateEndElement(schemaInfo);
            //Get XmlName, as memberType / validity might be set now
            if (psviAugmentation)
            {
                elementNode.XmlName = document.AddXmlName(elementNode.Prefix, elementNode.LocalName, elementNode.NamespaceURI, schemaInfo);
                if (schemaInfo.IsDefault)   //the element has a default value
                {
                    XmlText textNode = document.CreateTextNode(schemaInfo.SchemaElement.ElementDecl.DefaultValueRaw);
                    elementNode.AppendChild(textNode);
                }
            }

            nsManager.PopScope(); //Pop current namespace scope
        }
Example #36
0
        /// <summary>
        /// Save font. It will create this
        ///  <font Name="something" StemV="20" Width="[234 34]"><EmbeddedFont>dasjdlkajsdljxlkjsaldjasldjxflj</embeddedFont></font>
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="element"></param>
        public void Save(System.Xml.XmlDocument doc, System.Xml.XmlElement element)
        {
            // save font
            XmlElement   el   = doc.CreateElement("Font");
            XmlAttribute attr = doc.CreateAttribute("Name");

            attr.Value = this.Font.Name;
            el.SetAttributeNode(attr);

            attr       = doc.CreateAttribute("SaveID");
            attr.Value = this.SaveID.ToString();
            el.SetAttributeNode(attr);

            // save metrics
            attr       = doc.CreateAttribute("EmHeight");
            attr.Value = this.Font.FontFamily.GetEmHeight(this.Font.Style).ToString();
            el.SetAttributeNode(attr);

            attr       = doc.CreateAttribute("Ascent");
            attr.Value = this.Font.FontFamily.GetCellAscent(this.font.Style).ToString();
            el.SetAttributeNode(attr);

            attr       = doc.CreateAttribute("Descent");
            attr.Value = this.Font.FontFamily.GetCellDescent(this.font.Style).ToString();
            el.SetAttributeNode(attr);

            attr       = doc.CreateAttribute("Bold");
            attr.Value = this.Font.Bold ? "1" : "0";
            el.SetAttributeNode(attr);

            attr       = doc.CreateAttribute("Italic");
            attr.Value = this.Font.Italic ? "1" : "0";
            el.SetAttributeNode(attr);

            //  Get font metrics to save some properties of font
            FontMetrics metrics = new FontMetrics(this.Font);

            attr       = doc.CreateAttribute("EmbeddingLicense");
            attr.Value = ((int)metrics.EmbeddingLicense).ToString();
            el.SetAttributeNode(attr);

            attr       = doc.CreateAttribute("ItalicAngle");
            attr.Value = metrics.ItalicAngle.ToString();
            el.SetAttributeNode(attr);

            attr = doc.CreateAttribute("BBoxLeft"); attr.Value = metrics.FontBBox.Left.ToString(); el.SetAttributeNode(attr);
            attr = doc.CreateAttribute("BBoxRight"); attr.Value = metrics.FontBBox.Right.ToString(); el.SetAttributeNode(attr);
            attr = doc.CreateAttribute("BBoxTop"); attr.Value = metrics.FontBBox.Top.ToString(); el.SetAttributeNode(attr);
            attr = doc.CreateAttribute("BBoxBottom"); attr.Value = metrics.FontBBox.Bottom.ToString(); el.SetAttributeNode(attr);

            attr       = doc.CreateAttribute("StemV");
            attr.Value = metrics.StemV.ToString();
            el.SetAttributeNode(attr);

            attr       = doc.CreateAttribute("Flags");
            attr.Value = metrics.Flags.ToString();
            el.SetAttributeNode(attr);

            attr = doc.CreateAttribute("FirstChar"); attr.Value = metrics.FirstChar.ToString(); el.SetAttributeNode(attr);
            attr = doc.CreateAttribute("LastChar"); attr.Value = metrics.LastChar.ToString(); el.SetAttributeNode(attr);

            // make glyph widths
            string glyphwidth = "[ ";

            for (int i = metrics.FirstChar; i <= metrics.LastChar; i++)
            {
                int gw = metrics.GetGlyphWidth(this.font, i);
                glyphwidth += gw.ToString() + " ";
            }
            glyphwidth += " ]";

            attr = doc.CreateAttribute("Widths"); attr.Value = glyphwidth; el.SetAttributeNode(attr);

            // embedd font if not std font
            if (!this.IsStandardFont)
            {
                byte[] fontBuffer = FontMetrics.GetFontData(this.Font);
                attr = doc.CreateAttribute("EmbeddedDecodedFontLength"); attr.Value = fontBuffer.Length.ToString(); el.SetAttributeNode(attr);

                XmlText textValue = doc.CreateTextNode("EmdeddedFont");
                textValue.Value = Convert.ToBase64String(fontBuffer);
                attr            = doc.CreateAttribute("EmbeddedFontLength"); attr.Value = textValue.Value.Length.ToString(); el.SetAttributeNode(attr);
                el.AppendChild(textValue);
            }
            element.AppendChild(el);
        }
Example #37
0
    protected void OnServerResponse(string raw, string apicall, IRequestCallback cb)
    {
        var uc         = apicall.Split("/"[0]);
        var controller = uc[0];
        var action     = uc[1];

        if (Debug.isDebugBuild)
        {
            Debug.Log(raw);
        }

        // Fire call complete event
        RoarManager.OnRoarNetworkEnd("no id");

        // -- Parse the Roar response
        // Unexpected server response
        if (raw == null || raw.Length == 0 || raw[0] != '<')
        {
            // Error: fire the error callback
            System.Xml.XmlDocument doc   = new System.Xml.XmlDocument();
            System.Xml.XmlElement  error = doc.CreateElement("error");
            doc.AppendChild(error);
            error.AppendChild(doc.CreateTextNode(raw));
            if (cb != null)
            {
                cb.OnRequest(
                    new Roar.RequestResult(
                        RoarExtensions.CreateXmlElement("error", raw),
                        IWebAPI.INVALID_XML_ERROR,
                        "Invalid server response"
                        ));
            }
            return;
        }

        System.Xml.XmlElement root = null;
        try
        {
            root = RoarExtensions.CreateXmlElement(raw);
            if (root == null)
            {
                throw new System.Xml.XmlException("CreateXmlElement returned null");
            }
        }
        catch (System.Xml.XmlException e)
        {
            if (cb != null)
            {
                cb.OnRequest(
                    new Roar.RequestResult(
                        RoarExtensions.CreateXmlElement("error", raw),
                        IWebAPI.INVALID_XML_ERROR,
                        e.ToString()
                        ));
            }
            return;
        }

        System.Xml.XmlElement io = root.SelectSingleNode("/roar/io") as System.Xml.XmlElement;
        if (io != null)
        {
            if (cb != null)
            {
                cb.OnRequest(
                    new Roar.RequestResult(
                        root,
                        IWebAPI.IO_ERROR,
                        io.InnerText
                        ));
            }
            return;
        }

        int    callback_code;
        string callback_msg = "";

        System.Xml.XmlElement actionElement = root.SelectSingleNode("/roar/" + controller + "/" + action) as System.Xml.XmlElement;

        if (actionElement == null)
        {
            if (cb != null)
            {
                cb.OnRequest(
                    new Roar.RequestResult(
                        RoarExtensions.CreateXmlElement("error", raw),
                        IWebAPI.INVALID_XML_ERROR,
                        "Incorrect XML response"
                        ));
            }
            return;
        }

        // Pre-process <server> block if any and attach any processed data
        System.Xml.XmlElement serverElement = root.SelectSingleNode("/roar/server") as System.Xml.XmlElement;
        RoarManager.NotifyOfServerChanges(serverElement);

        // Status on Server returned an error. Action did not succeed.
        string status = actionElement.GetAttribute("status");

        if (status == "error")
        {
            callback_code = IWebAPI.UNKNOWN_ERR;
            callback_msg  = actionElement.SelectSingleNode("error").InnerText;
            string server_error = (actionElement.SelectSingleNode("error") as System.Xml.XmlElement).GetAttribute("type");
            if (server_error == "0")
            {
                if (callback_msg == "Must be logged in")
                {
                    callback_code = IWebAPI.UNAUTHORIZED;
                }
                if (callback_msg == "Invalid auth_token")
                {
                    callback_code = IWebAPI.UNAUTHORIZED;
                }
                if (callback_msg == "Must specify auth_token")
                {
                    callback_code = IWebAPI.BAD_INPUTS;
                }
                if (callback_msg == "Must specify name and hash")
                {
                    callback_code = IWebAPI.BAD_INPUTS;
                }
                if (callback_msg == "Invalid name or password")
                {
                    callback_code = IWebAPI.DISALLOWED;
                }
                if (callback_msg == "Player already exists")
                {
                    callback_code = IWebAPI.DISALLOWED;
                }

                logger.DebugLog(string.Format("[roar] -- response error: {0} (api call = {1})", callback_msg, apicall));
            }

            // Error: fire the callback
            // NOTE: The Unity version ASSUMES callback = errorCallback
            if (cb != null)
            {
                cb.OnRequest(new Roar.RequestResult(root, callback_code, callback_msg));
            }
        }

        // No error - pre-process the result
        else
        {
            System.Xml.XmlElement auth_token = actionElement.SelectSingleNode(".//auth_token") as System.Xml.XmlElement;
            if (auth_token != null && !string.IsNullOrEmpty(auth_token.InnerText))
            {
                RoarAuthToken = auth_token.InnerText;
            }

            callback_code = IWebAPI.OK;
            if (cb != null)
            {
                cb.OnRequest(new Roar.RequestResult(root, callback_code, callback_msg));
            }
        }

        RoarManager.OnCallComplete(new RoarManager.CallInfo(root, callback_code, callback_msg, "no id"));
    }
Example #38
0
        /// <summary>
        /// Adds the active assemblies to a plugin file
        /// </summary>
        private static void AddAssembliesToPluginFile(string PluginFolder, string PluginClass, Xml.XmlDocument PluginLibrary, Type[] PluginTypes)
        {
            if (System.IO.Directory.Exists(PluginFolder))
            {
                foreach (string PluginFile in System.IO.Directory.GetFiles(PluginFolder, "*.dll"))
                {
                    bool   FoundOne    = false;
                    string OldFileName = PluginFile.Substring(PluginFile.LastIndexOf("\\") + 1);
                    string NewFileName = ".\\plugins\\tmp\\"; //huangxy

                    if (!Directory.Exists(NewFileName))
                    {
                        Directory.CreateDirectory(NewFileName);
                    }
                    NewFileName += OldFileName + ".tmp";

                    File.Copy(PluginFile, NewFileName, true);

                    System.Reflection.Assembly PluginAssembly = System.Reflection.Assembly.LoadFile(Path.GetFullPath(NewFileName));
                    System.Type[] types = null;
                    try
                    {
                        types = PluginAssembly.GetTypes();
                    }catch (Exception e) {
                        Console.WriteLine(e.Message);
                    }
                    if (types == null)
                    {
                        continue;
                    }
                    foreach (System.Type NewType in types)
                    {
                        bool Found = false;

                        foreach (System.Type InterfaceType in NewType.GetInterfaces())
                        {
                            foreach (System.Type DesiredType in PluginTypes)
                            {
                                if (InterfaceType == DesiredType)
                                {
                                    string ClassName = NewType.Name.ToLower();
                                    if (NewType.Namespace != null)
                                    {
                                        ClassName = NewType.Namespace.ToLower() + "." + ClassName;
                                    }

                                    FoundOne = true;
                                    Xml.XmlElement NewNode = PluginLibrary.CreateElement("plugin");
                                    NewNode.SetAttribute("library", OldFileName);
                                    NewNode.SetAttribute("interface", DesiredType.Name);
                                    NewNode.SetAttribute("name", NewType.Name.ToLower());
                                    NewNode.SetAttribute("fullname", ClassName);
                                    NewNode.AppendChild(PluginLibrary.CreateTextNode(NewFileName));

                                    Xml.XmlElement Parent = (Xml.XmlElement)PluginLibrary.SelectSingleNode("/plugins/active[@type='" + PluginClass + "']");
                                    if (Parent == null)
                                    {
                                        Parent = PluginLibrary.CreateElement("active");
                                        Parent.SetAttribute("type", PluginClass);
                                        PluginLibrary.SelectSingleNode("/plugins").AppendChild(Parent);
                                    }
                                    Parent.AppendChild(NewNode);
                                    Parent.SetAttribute("updated", System.DateTime.Now.ToString());

                                    Found = true;
                                    break;
                                }
                                if (Found)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    if (!FoundOne)
                    {
                        Xml.XmlElement NewNode = PluginLibrary.CreateElement("plugin");
                        NewNode.AppendChild(PluginLibrary.CreateTextNode(NewFileName));

                        PluginLibrary.SelectSingleNode("/plugins/retired").AppendChild(NewNode);
                        PluginLibrary.DocumentElement.SetAttribute("updated", System.DateTime.Now.ToString());
                    }
                }
            }
        }
Example #39
0
        private XmlNode LoadNode(bool skipOverWhitespace)
        {
            XmlReader  r      = _reader;
            XmlNode    parent = null;
            XmlElement element;

            do
            {
                XmlNode node = null;
                switch (r.NodeType)
                {
                case XmlNodeType.Element:
                    bool fEmptyElement = r.IsEmptyElement;
                    element         = _doc.CreateElement(r.Prefix, r.LocalName, r.NamespaceURI);
                    element.IsEmpty = fEmptyElement;

                    if (r.MoveToFirstAttribute())
                    {
                        XmlAttributeCollection attributes = element.Attributes;
                        do
                        {
                            XmlAttribute attr = LoadAttributeNode();
                            attributes.Append(attr);     // special case for load
                        }while (r.MoveToNextAttribute());
                        r.MoveToElement();
                    }

                    // recursively load all children.
                    if (!fEmptyElement)
                    {
                        if (parent != null)
                        {
                            parent.AppendChildForLoad(element, _doc);
                        }
                        parent = element;
                        continue;
                    }
                    else
                    {
                        node = element;
                        break;
                    }

                case XmlNodeType.EndElement:
                    if (parent == null)
                    {
                        return(null);
                    }
                    Debug.Assert(parent.NodeType == XmlNodeType.Element);
                    if (parent.ParentNode == null)
                    {
                        return(parent);
                    }
                    parent = parent.ParentNode;
                    continue;

                case XmlNodeType.EntityReference:
                    node = LoadEntityReferenceNode(false);
                    break;

                case XmlNodeType.EndEntity:
                    Debug.Assert(parent == null);
                    return(null);

                case XmlNodeType.Attribute:
                    node = LoadAttributeNode();
                    break;

                case XmlNodeType.Text:
                    node = _doc.CreateTextNode(r.Value);
                    break;

                case XmlNodeType.SignificantWhitespace:
                    node = _doc.CreateSignificantWhitespace(r.Value);
                    break;

                case XmlNodeType.Whitespace:
                    if (_preserveWhitespace)
                    {
                        node = _doc.CreateWhitespace(r.Value);
                        break;
                    }
                    else if (parent == null && !skipOverWhitespace)
                    {
                        // if called from LoadEntityReferenceNode, just return null
                        return(null);
                    }
                    else
                    {
                        continue;
                    }

                case XmlNodeType.CDATA:
                    node = _doc.CreateCDataSection(r.Value);
                    break;


                case XmlNodeType.XmlDeclaration:
                    node = LoadDeclarationNode();
                    break;

                case XmlNodeType.ProcessingInstruction:
                    node = _doc.CreateProcessingInstruction(r.Name, r.Value);
                    break;

                case XmlNodeType.Comment:
                    node = _doc.CreateComment(r.Value);
                    break;

                case XmlNodeType.DocumentType:
                    node = LoadDocumentTypeNode();
                    break;

                default:
                    throw UnexpectedNodeType(r.NodeType);
                }

                Debug.Assert(node != null);
                if (parent != null)
                {
                    parent.AppendChildForLoad(node, _doc);
                }
                else
                {
                    return(node);
                }
            }while (r.Read());

            // when the reader ended before full subtree is read, return whatever we have created so far
            if (parent != null)
            {
                while (parent.ParentNode != null)
                {
                    parent = parent.ParentNode;
                }
            }
            return(parent);
        }