Example #1
0
        public override System.Xml.XmlDocument ToXml()
        {
            System.Xml.XmlDocument xmlDoc = base.ToXml();

            System.Xml.XmlElement xmlTypeEl = xmlDoc.CreateElement(XmlPropType);
            System.Xml.XmlNode    xmlType   = xmlDoc.CreateNode(System.Xml.XmlNodeType.Text, XmlPropType, String.Empty);
            xmlType.Value = this.GetType().ToString();
            xmlTypeEl.AppendChild(xmlType);

            System.Xml.XmlElement xmlURLEl = xmlDoc.CreateElement(XmlPropURL);
            System.Xml.XmlNode    xmlURL   = xmlDoc.CreateNode(System.Xml.XmlNodeType.Text, XmlPropURL, String.Empty);
            xmlURL.Value = URL;
            xmlURLEl.AppendChild(xmlURL);

            System.Xml.XmlElement xmlUsernameEl = xmlDoc.CreateElement(XmlPropUser);
            System.Xml.XmlNode    xmlUsername   = xmlDoc.CreateNode(System.Xml.XmlNodeType.Text, XmlPropUser, String.Empty);
            xmlUsername.Value = Username;
            xmlUsernameEl.AppendChild(xmlUsername);

            System.Xml.XmlElement xmlPasswordEl = xmlDoc.CreateElement(XmlPropPass);
            System.Xml.XmlNode    xmlPassword   = xmlDoc.CreateNode(System.Xml.XmlNodeType.Text, XmlPropPass, String.Empty);
            xmlPassword.Value = Password;
            xmlPasswordEl.AppendChild(xmlPassword);

            xmlDoc.ChildNodes[0].AppendChild(xmlTypeEl);
            xmlDoc.ChildNodes[0].AppendChild(xmlURLEl);
            xmlDoc.ChildNodes[0].AppendChild(xmlUsernameEl);
            xmlDoc.ChildNodes[0].AppendChild(xmlPasswordEl);

            return(xmlDoc);
        }
Example #2
0
        public static string ReplyImage(ReplyImageModel entity)
        {
            if (null != entity && !string.IsNullOrWhiteSpace(entity.ToUserName) && null != entity.Image)
            {
                string xmlString = string.Empty;
                //var s1 = XmlHelper.Serialize(entity);
                #region xmlString
                System.Xml.XmlDocument     xmlDoc = new System.Xml.XmlDocument();
                System.Xml.XmlNode         rootNode;
                System.Xml.XmlElement      ele;
                System.Xml.XmlCDataSection cdata;

                #region xml
                rootNode = xmlDoc.CreateNode(System.Xml.XmlNodeType.Element, "xml", null);

                ele   = xmlDoc.CreateElement(nameof(entity.ToUserName));
                cdata = xmlDoc.CreateCDataSection(entity.ToUserName);
                ele.AppendChild(cdata);
                rootNode.AppendChild(ele);

                ele   = xmlDoc.CreateElement(nameof(entity.FromUserName));
                cdata = xmlDoc.CreateCDataSection(entity.FromUserName);
                ele.AppendChild(cdata);
                rootNode.AppendChild(ele);

                ele          = xmlDoc.CreateElement(nameof(entity.CreateTime));
                ele.InnerXml = entity.CreateTime.ToString();
                rootNode.AppendChild(ele);

                ele   = xmlDoc.CreateElement(nameof(entity.MsgType));
                cdata = xmlDoc.CreateCDataSection(entity.MsgType);
                ele.AppendChild(cdata);
                rootNode.AppendChild(ele);
                #endregion

                System.Xml.XmlNode nodeImage;
                nodeImage = xmlDoc.CreateNode(System.Xml.XmlNodeType.Element, nameof(entity.Image), null);
                if (null != entity.Image)
                {
                    ele   = xmlDoc.CreateElement(nameof(entity.Image.MediaId));
                    cdata = xmlDoc.CreateCDataSection(entity.Image.MediaId);
                    ele.AppendChild(cdata);
                    nodeImage.AppendChild(ele);
                }

                rootNode.AppendChild(nodeImage);
                xmlDoc.AppendChild(rootNode);

                xmlString = xmlDoc.OuterXml;
                #endregion

                if (!string.IsNullOrWhiteSpace(xmlString))
                {
                    return(xmlString);
                }
            }
            return(ReplyEmpty());
        }
Example #3
0
        private void btnPublishFolder_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(txtFolderPath.Text))
            {
                //To Publish Folder, add Data to XML
                System.Xml.XmlDocument objXmlDocument = new System.Xml.XmlDocument();
                // Load XML
                objXmlDocument.Load(@".\Data\PublishedFolders.xml");
                System.Xml.XmlNode objXmlNode = objXmlDocument.CreateNode(System.Xml.XmlNodeType.Element,"Folder", "Folder");

                // Attribute Name
                System.Xml.XmlAttribute objXmlAttribute = objXmlDocument.CreateAttribute("Name");
                objXmlAttribute.Value = "Carpeta";
                objXmlNode.Attributes.Append(objXmlAttribute);
                // Attribute Status
                objXmlAttribute = objXmlDocument.CreateAttribute("Status");
                objXmlAttribute.Value = "Enabled";
                objXmlNode.Attributes.Append(objXmlAttribute);
                // Attribute Path
                objXmlAttribute = objXmlDocument.CreateAttribute("Path");
                objXmlAttribute.Value = txtFolderPath.Text;
                objXmlNode.Attributes.Append(objXmlAttribute);

                // Add Node
                objXmlDocument.SelectSingleNode("/PublishedFolders").AppendChild(objXmlNode);
                // Update File
                objXmlDocument.Save(@".\Data\PublishedFolders.xml");

                // Refresh List
                LoadFolders();
            }
        }
Example #4
0
 public void SaveReminders()
 {
     System.Xml.XmlDocument reminders = new System.Xml.XmlDocument();
     reminders.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><reminders />");
     for (int i = 0; i < mReminders.Count; i++)
     {
         System.Xml.XmlNode rem = reminders.CreateNode(System.Xml.XmlNodeType.Element, "reminderItem", "");
         rem.AppendChild(reminders.CreateNode(System.Xml.XmlNodeType.Element, "when", ""));
         rem.AppendChild(reminders.CreateNode(System.Xml.XmlNodeType.Element, "fired", ""));
         rem.AppendChild(reminders.CreateNode(System.Xml.XmlNodeType.Element, "reminder", ""));
         clsReminderEntry re = (clsReminderEntry)mReminders[i];
         rem.SelectSingleNode("when").InnerText     = re.when;
         rem.SelectSingleNode("fired").InnerText    = re.fired;
         rem.SelectSingleNode("reminder").InnerText = re.reminder;
         reminders.DocumentElement.AppendChild(rem);
     }
     reminders.Save(ReminderFilePath());
 }
Example #5
0
        /// <summary>
        /// Given an xml document, an element in that document, and a name/value pair, it will create a child element,
        /// properly CDATA-escaped, with the given name and value. Note that the name must be a valid XML tag name.
        /// </summary>
        public static void CreateCDATAElement(System.Xml.XmlDocument xmlDoc, System.Xml.XmlElement parent, string elemName, string elemValue)
        {
            System.Xml.XmlElement xmlTempElem = null;
            System.Xml.XmlNode    xmlTempNode = null;

            xmlTempElem           = xmlDoc.CreateElement(elemName);
            xmlTempNode           = xmlDoc.CreateNode(System.Xml.XmlNodeType.CDATA, "", "");
            xmlTempNode.InnerText = elemValue;
            xmlTempElem.AppendChild(xmlTempNode);
            parent.AppendChild(xmlTempElem);
        }
        /// <summary>
        /// Returns an Xml document containing information on all of the functions in the TemplateGen
        /// type from the current assembly
        /// </summary>
        /// <returns></returns>
        public string GetFunctionsXml()
        {
            object obj     = CurrentAssembly.CreateInstance(_ProjectNamespace + ".TemplateGen");
            Type   objType = obj.GetType();

            MethodInfo[] methods = objType.GetMethods(BindingFlags.Public | BindingFlags.Static);

            System.Xml.XmlDocument doc      = new System.Xml.XmlDocument();
            System.Xml.XmlNode     rootNode = doc.CreateNode(System.Xml.XmlNodeType.Element, "functions", "");

            foreach (MethodInfo method in methods)
            {
                System.Xml.XmlNode      functionNode = doc.CreateNode(System.Xml.XmlNodeType.Element, "function", "");
                System.Xml.XmlAttribute attName      = doc.CreateAttribute("name");
                attName.Value = method.Name;
                System.Xml.XmlAttribute attParamTypeName = doc.CreateAttribute("parametertypename");
                ParameterInfo[]         parameters       = method.GetParameters();

                switch (parameters.Length)
                {
                case 0:
                    attParamTypeName.Value = "";
                    break;

                case 1:
                    attParamTypeName.Value = parameters[0].ParameterType.ToString();
                    break;

                default:
                    attParamTypeName.Value = parameters[0].ParameterType.ToString();
                    // TODO: Determine how to handle Template vs. normal functions WRT number of parameters
                    //throw new Exception("Template functions can't have more than one parameter: "+ method.Name);
                    break;
                }
                functionNode.Attributes.Append(attName);
                functionNode.Attributes.Append(attParamTypeName);
                rootNode.AppendChild(functionNode);
            }
            doc.AppendChild(rootNode);
            return(doc.OuterXml);
        }
Example #7
0
        /// <summary>
        /// Serialize the object to XML
        /// </summary>
        /// <returns></returns>
        public override System.Xml.XmlDocument ToXml()
        {
            DateTime Start = Debug.ExecStart;

            System.Xml.XmlDocument xmlDoc = base.ToXml();

            System.Xml.XmlElement xmlTypeEl = xmlDoc.CreateElement(XmlPropType);
            System.Xml.XmlNode    xmlType   = xmlDoc.CreateNode(System.Xml.XmlNodeType.Text, XmlPropType, String.Empty);
            xmlType.Value = this.GetType().ToString();
            xmlTypeEl.AppendChild(xmlType);

            System.Xml.XmlElement xmlPathEl = xmlDoc.CreateElement(XmlPropPath);
            System.Xml.XmlNode    xmlPath   = xmlDoc.CreateNode(System.Xml.XmlNodeType.Text, XmlPropPath, String.Empty);
            xmlPath.Value = Path;
            xmlPathEl.AppendChild(xmlPath);

            xmlDoc.ChildNodes[0].AppendChild(xmlTypeEl);
            xmlDoc.ChildNodes[0].AppendChild(xmlPathEl);

            ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), "");
            return(xmlDoc);
        }
        /// <summary>
        /// Given an xml document, an element in that document, and a name/value pair, it will create a child element,
        /// properly CDATA-escaped, with the given name and value. Note that the name must be a valid XML tag name.
        /// </summary>
        private void CreateCDATAElement(System.Xml.XmlDocument xmlDoc, System.Xml.XmlElement parent, string elemName, string elemValue)
        {
            System.Xml.XmlElement xmlTempElem = null;
            System.Xml.XmlNode    xmlTempNode = null;

            // CONSIDER: According to docs, setting InnerText properties has changed to now do proper escaping of the
            // value. Encompassing every created item in a CDATA element may no longer be necessary through the framework.
            xmlTempElem           = xmlDoc.CreateElement(elemName);
            xmlTempNode           = xmlDoc.CreateNode(System.Xml.XmlNodeType.CDATA, "", "");
            xmlTempNode.InnerText = elemValue;
            xmlTempElem.AppendChild(xmlTempNode);
            parent.AppendChild(xmlTempElem);
        }
Example #9
0
 public void Initialize()
 {
     try
     {
         config = new System.Xml.XmlDocument();
         var elmnt = config.CreateElement("UserConfig");
         config.AppendChild(elmnt);
         var node = config.CreateNode(System.Xml.XmlNodeType.Element, "COMMON", null);
         elmnt.AppendChild(node);
     }
     catch (Exception)
     {
     }
 }
 static void Main(string[] args)
 {
     var csvData = ReadCsvDataFromFile();
     var doc = new System.Xml.XmlDocument();
     for (var i = 0; i < csvData.Length; i++)
     {
         var csvRowAsArray = csvData[i];
         var recordHeader = doc.CreateElement("CUSTOMERPAYMENTJOURNALHEADERENTITY");
         var jbatchnumTag = doc.CreateNode(XmlNodeType.Element, "JOURNALBATCHNUMBER", "");
         jbatchnumTag.InnerText = csvRowAsArray[0];
         recordHeader.AppendChild(jbatchnumTag);
         var descTag = doc.CreateNode(XmlNodeType.Element, "DESCRIPTION", "");
         //descTag.InnerText = ??
         recordHeader.AppendChild(descTag);
         var jnameTag = doc.CreateNode(XmlNodeType.Element, "JOURNALNAME", "");
         //jnameTag.InnerText = ???
         recordHeader.AppendChild(jnameTag);
         var customerRecord = doc.CreateElement("CUSTOMERPAYMENTJOURNALENTITY");
         var jbatchnumTag2 = doc.CreateNode(XmlNodeType.Element, "JOURNALBATCHNUMBER", "");
         jbatchnumTag2.InnerText = csvRowAsArray[0];
         customerRecord.AppendChild(jbatchnumTag2);
         var lineNumTag = doc.CreateNode(XmlNodeType.Element, "LINENUMBER", "");
         lineNumTag.InnerText = csvRowAsArray[2];
         customerRecord.AppendChild(lineNumTag);
         var accountDisplayTag = doc.CreateNode(XmlNodeType.Element, "ACCOUNTDISPLAYVALUE", "");
         accountDisplayTag.InnerText = csvRowAsArray[3];
         customerRecord.AppendChild(accountDisplayTag);
         var accountTypeTag = doc.CreateNode(XmlNodeType.Element, "ACCOUNTTYPE", "");
         accountTypeTag.InnerText = csvRowAsArray[3];
         customerRecord.AppendChild(accountDisplayTag);
         var bankTransactionTypeTag = doc.CreateNode(XmlNodeType.Element, "BANKTRANSACTIONTYPE", "");
         bankTransactionTypeTag.InnerText = csvRowAsArray[5];
         customerRecord.AppendChild(bankTransactionTypeTag);
         var voucherTag = doc.CreateNode(XmlNodeType.Element, "VOUCHER", "");
         voucherTag.InnerText = csvRowAsArray[1];
         customerRecord.AppendChild(voucherTag);
         recordHeader.AppendChild(customerRecord);
         doc.AppendChild(recordHeader);
     }
     doc.Save(@"test.xml");
 }
Example #11
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            string path = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + @"\data\produkter.xml";

            if (this.productName != "NEW")
            {
                XDocument xmlFile = XDocument.Load(path);
                var       query   = from c in xmlFile.Elements("produkter").Elements("produkt")
                                    where (string)(c.Element("pnamn")) == this.productName
                                    select c;
                foreach (XElement foretag in query)
                {
                    foretag.Element("pnamn").Value = textBoxName.Text;
                    foretag.Element("pris").Value  = textBoxPris.Text;
                }
                xmlFile.Save(path);
            }
            else
            {
                string filename = path;

                //create new instance of XmlDocument
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

                //load from file
                doc.Load(filename);

                //create node and add value
                System.Xml.XmlNode node = doc.CreateNode(System.Xml.XmlNodeType.Element, "produkt", null);

                System.Xml.XmlNode nodeNamn = doc.CreateElement("pnamn");
                nodeNamn.InnerText = textBoxName.Text;

                System.Xml.XmlNode nodeER = doc.CreateElement("pris");
                nodeER.InnerText = textBoxPris.Text;

                //add to parent node
                node.AppendChild(nodeNamn);
                node.AppendChild(nodeER);

                //add to elements collection
                doc.DocumentElement.AppendChild(node);

                //save back
                doc.Save(filename);
            }
            toolStripStatusLabel1.Text = "Sparade";
        }
Example #12
0
        private static void AddRepo(string path, string name)
        {
            var rootPath   = Path.GetDirectoryName(typeof(Program).Assembly.Location);
            var repoConfig = Path.Combine(rootPath, Constants.RepoList);

            if (!File.Exists(repoConfig))
            {
                var sr = File.CreateText(repoConfig);
                using (sr)
                {
                    sr.Write(@"<?xml version=""1.0"" encoding=""utf-8""?>");
                    sr.WriteLine();
                    sr.Write("<repos>");
                    sr.WriteLine();
                    sr.Write("</repos>");
                }
            }

            if (name == null)
            {
                name = "";
            }

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

            doc.LoadXml(File.ReadAllText(repoConfig));

            if (doc.DocumentElement.SelectSingleNode($"descendant::repo[@path='{path}' and @name='{name}']") != null)
            {
                return;
            }

            var node = doc.CreateNode(System.Xml.XmlNodeType.Element, "repo", null);
            var attr = doc.CreateAttribute("path");

            attr.Value = path;
            node.Attributes.Append(attr);

            attr       = doc.CreateAttribute("name");
            attr.Value = name;
            node.Attributes.Append(attr);

            doc.SelectSingleNode("repos").AppendChild(node);
            doc.Save(repoConfig);
        }
Example #13
0
        internal static System.Xml.XmlNode CreateXMLNodes(XMLData data)
        {
            System.Xml.XmlNode xNode = xDoc.CreateNode(System.Xml.XmlNodeType.Element,
                                                       "Monitee", null);

            System.Xml.XmlElement name     = xDoc.CreateElement("Source");
            System.Xml.XmlElement type     = xDoc.CreateElement("Type");
            System.Xml.XmlElement destPath = xDoc.CreateElement("Destination");
            name.InnerText     = data.MoniteePath;
            type.InnerText     = data.Type.ToString();
            destPath.InnerText = data.DestinationPath;

            xNode.AppendChild(name);
            xNode.AppendChild(type);
            xNode.AppendChild(destPath);

            return(xNode);
        }
Example #14
0
        private static void AddPackageToConfig(string folder, string id, string version, string targetFramework = null)
        {
            CreatePackageConfig(folder);

            var configFileName = Path.Combine(folder, "packages.config");
            var doc            = new System.Xml.XmlDocument();

            doc.LoadXml(File.ReadAllText(configFileName));
            var nodes = doc.DocumentElement.SelectSingleNode($"descendant::package");

            if (nodes != null)
            {
                foreach (System.Xml.XmlNode xnode in nodes)
                {
                    var node_id      = xnode.Attributes["id"]?.Value;
                    var node_version = xnode.Attributes["version"]?.Value;
                    if (id.Equals(node_id, StringComparison.InvariantCultureIgnoreCase) &&
                        version.Equals(node_version, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return;
                    }
                }
            }

            var node = doc.CreateNode(System.Xml.XmlNodeType.Element, "package", null);
            var attr = doc.CreateAttribute("id");

            attr.Value = id;
            node.Attributes.Append(attr);

            attr       = doc.CreateAttribute("version");
            attr.Value = version;
            node.Attributes.Append(attr);

            if (!string.IsNullOrWhiteSpace(targetFramework))
            {
                attr       = doc.CreateAttribute("targetFramework");
                attr.Value = targetFramework;
                node.Attributes.Append(attr);
            }

            doc.SelectSingleNode("packages").AppendChild(node);
            doc.Save(configFileName);
        }
Example #15
0
        public static bool SaveDataToXML(string DictName, string NodeName, string ElementName, string ElementID, string ElementData, out string ErrorMsg)
        {
            if (_xml == null)
            {
                LoadXML();
            }

            System.Xml.XmlNode xNode = _xml.SelectSingleNode(string.Format("/root/{0}/{1}[@{2}='{3}']", DictName, NodeName, ElementName, ElementID));
            if (xNode != null)
            {
                xNode.InnerText = ElementData;
            }
            else
            {
                try
                {
                    System.Xml.XmlNode xRoot = _xml.SelectSingleNode("/root/" + DictName);
                    if (xRoot == null)
                    {
                        xRoot = _xml.CreateNode(System.Xml.XmlNodeType.Element, DictName, null);
                        if (_xml.ChildNodes.Count > 0)
                        {
                            _xml.DocumentElement.AppendChild(xRoot);
                        }
                        else
                        {
                            _xml.AppendChild(xRoot);
                        }
                    }
                    System.Xml.XmlElement xElm = _xml.CreateElement(NodeName);
                    xElm.SetAttribute(ElementName, ElementID);
                    xElm.InnerText = ElementData;
                    xRoot.AppendChild(xElm);
                    _xml.Save(_xmlpath);
                }
                catch (Exception ex)
                {
                    ErrorMsg = ex.Message;
                    return(false);
                }
            }
            ErrorMsg = "";
            return(true);
        }
Example #16
0
        public void Save(string filename)
        {
            string tmpfilename = filename + ".tmp";

            System.IO.FileStream   stream = new System.IO.FileStream(tmpfilename, System.IO.FileMode.Create, System.IO.FileAccess.Write);
            System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);

            // 형식 정보 쓰자
            byte[] magicbyte   = new byte[52];
            string magicstring = string.Format("KOG GC TEAM MASSFILE V.{0}.{1}.", version / 10, version % 10);


            System.Text.ASCIIEncoding.ASCII.GetBytes(magicstring, 0, magicstring.Length, magicbyte, 0);
            writer.Write(magicbyte);

            filetime = 0;
            foreach (System.Collections.Generic.KeyValuePair <string, Kom2SubFile> KeyValue in subfiles)
            {
                filetime += KeyValue.Value.FileTime;
            }

            // 헤더는 xml 형식

            System.Xml.XmlDocument headerxml = new System.Xml.XmlDocument();
            headerxml.AppendChild(headerxml.CreateNode(System.Xml.XmlNodeType.XmlDeclaration, "", ""));

            System.Xml.XmlElement files = headerxml.CreateElement("Files");
            headerxml.AppendChild(files);

            foreach (System.Collections.Generic.KeyValuePair <string, Kom2SubFile> KeyValue in subfiles)
            {
                System.Xml.XmlElement file = headerxml.CreateElement("File");

                file.SetAttribute("Name", KeyValue.Key);
                KeyValue.Value.WriteHeader(file);
                files.AppendChild(file);
            }

            int header_raw_size = headerxml.InnerXml.Length;

            if (header_raw_size % BlowfishNET.BlowfishECB.BLOCK_SIZE != 0)
            {
                header_raw_size += BlowfishNET.BlowfishECB.BLOCK_SIZE - (header_raw_size % BlowfishNET.BlowfishECB.BLOCK_SIZE);
            }


            byte[] header_raw = new byte[header_raw_size];

            System.Text.ASCIIEncoding.ASCII.GetBytes(headerxml.InnerXml, 0, headerxml.InnerXml.Length, header_raw, 0);

            if (ecb != null)
            {
                byte[] header_encrypt = (byte [])header_raw.Clone();
                int    a = ecb.Encrypt(header_encrypt, 0, header_raw, 0, header_raw.Length);
            }

            writer.Write((UInt32)subfiles.Count);
            writer.Write((UInt32)1);
            writer.Write(FileTime);                                                         // 파일타임
            writer.Write(AdlerCheckSum.GetAdler32(header_raw, 0, (uint)header_raw.Length)); // 체크섬
            writer.Write((UInt32)header_raw.Length);                                        // 압축 안한 사이즈
            writer.Write(header_raw, 0, (int)header_raw.Length);                            // 헤더


            foreach (System.Collections.Generic.KeyValuePair <string, Kom2SubFile> KeyValue in subfiles)
            {
                KeyValue.Value.WriteCompressed(writer.BaseStream);
            }

            stream.Close();
            System.IO.File.Delete(filename);
            System.IO.File.Move(tmpfilename, filename);
        }
Example #17
0
        /// <summary>
        /// Returns an Xml document containing information on all of the functions in the TemplateGen
        /// type from the current assembly
        /// </summary>
        /// <returns></returns>
        public string GetFunctionsXml()
        {
            object obj = CurrentAssembly.CreateInstance(_ProjectNamespace + ".TemplateGen");
            Type objType = obj.GetType();

            MethodInfo[] methods = objType.GetMethods(BindingFlags.Public | BindingFlags.Static);

            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            System.Xml.XmlNode rootNode = doc.CreateNode(System.Xml.XmlNodeType.Element, "functions", "");

            foreach (MethodInfo method in methods)
            {
                System.Xml.XmlNode functionNode = doc.CreateNode(System.Xml.XmlNodeType.Element, "function", "");
                System.Xml.XmlAttribute attName = doc.CreateAttribute("name");
                attName.Value = method.Name;
                System.Xml.XmlAttribute attParamTypeName = doc.CreateAttribute("parametertypename");
                ParameterInfo[] parameters = method.GetParameters();

                switch (parameters.Length)
                {
                    case 0:
                        attParamTypeName.Value = "";
                        break;
                    case 1:
                        attParamTypeName.Value = parameters[0].ParameterType.ToString();
                        break;
                    default:
                        attParamTypeName.Value = parameters[0].ParameterType.ToString();
                        // TODO: Determine how to handle Template vs. normal functions WRT number of parameters
                        //throw new Exception("Template functions can't have more than one parameter: "+ method.Name);
                        break;
                }
                functionNode.Attributes.Append(attName);
                functionNode.Attributes.Append(attParamTypeName);
                rootNode.AppendChild(functionNode);
            }
            doc.AppendChild(rootNode);
            return doc.OuterXml;
        }
Example #18
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            string path = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + @"\data\kunder.xml";

            if (this.customerID != "NEW")
            {
                XDocument xmlFile = XDocument.Load(path);
                var       query   = from c in xmlFile.Elements("customers").Elements("kund")
                                    where (string)(c.Element("kundnr")) == this.customerID
                                    select c;
                foreach (XElement foretag in query)
                {
                    foretag.Element("namn").Value           = tbForetagName.Text;
                    foretag.Element("kundnr").Value         = tbKundNr.Text;
                    foretag.Element("er").Value             = tbEr.Text;
                    foretag.Element("fakturaadress1").Value = tbAddress1.Text;
                    foretag.Element("fakturaadress2").Value = tbAddress2.Text;
                    foretag.Element("fakturaadress3").Value = tbAddress3.Text;
                    foretag.Element("fakturaemail").Value   = tbEmail.Text;
                    foretag.Element("momsregnr").Value      = tbMomsRegNr.Text;
                }
                xmlFile.Save(path);
            }
            else
            {
                //file name
                string filename = path;

                //create new instance of XmlDocument
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

                //load from file
                doc.Load(filename);

                //create node and add value
                System.Xml.XmlNode node = doc.CreateNode(System.Xml.XmlNodeType.Element, "kund", null);

                System.Xml.XmlNode nodeNamn = doc.CreateElement("namn");
                nodeNamn.InnerText = tbForetagName.Text;

                System.Xml.XmlNode nodeER = doc.CreateElement("er");
                nodeER.InnerText = tbEr.Text;

                System.Xml.XmlNode nodeKundNR = doc.CreateElement("kundnr");
                nodeKundNR.InnerText = this.newKundNummer.ToString();//tbKundNr.Text;

                System.Xml.XmlNode nodeMomsRegNr = doc.CreateElement("momsregnr");
                nodeMomsRegNr.InnerText = tbMomsRegNr.Text;

                System.Xml.XmlNode nodeAddress1 = doc.CreateElement("fakturaadress1");
                nodeAddress1.InnerText = tbAddress1.Text;
                System.Xml.XmlNode nodeAddress2 = doc.CreateElement("fakturaadress2");
                nodeAddress2.InnerText = tbAddress2.Text;
                System.Xml.XmlNode nodeAddress3 = doc.CreateElement("fakturaadress3");
                nodeAddress3.InnerText = tbAddress3.Text;

                System.Xml.XmlNode nodeEmail = doc.CreateElement("fakturaemail");
                nodeEmail.InnerText = tbEmail.Text;

                //add to parent node
                node.AppendChild(nodeNamn);
                node.AppendChild(nodeER);
                node.AppendChild(nodeKundNR);
                node.AppendChild(nodeMomsRegNr);
                node.AppendChild(nodeAddress1);
                node.AppendChild(nodeAddress2);
                node.AppendChild(nodeAddress3);
                node.AppendChild(nodeEmail);

                //add to elements collection
                doc.DocumentElement.AppendChild(node);

                //save back
                doc.Save(filename);
            }
        }
Example #19
0
        System.Xml.XmlDocument Decompress(byte[] buffer)
        {
            var decompressBuffer = Utils.Zlib.Decompress(buffer);

            var doc    = new System.Xml.XmlDocument();
            var reader = new Utl.BinaryReader(decompressBuffer);

            var   keys    = new Dictionary <Int16, string>();
            Int16 keySize = -1;

            reader.Get(ref keySize);
            for (int i = 0; i < keySize; i++)
            {
                Int16  key  = -1;
                string name = "";
                reader.Get(ref name, Encoding.UTF8, false, 2);
                reader.Get(ref key);
                keys.Add(key, name);
            }

            var   values    = new Dictionary <Int16, string>();
            Int16 valueSize = -1;

            reader.Get(ref valueSize);
            for (int i = 0; i < valueSize; i++)
            {
                Int16  key   = -1;
                string value = "";
                reader.Get(ref value, Encoding.UTF8, false, 2);
                reader.Get(ref key);
                values.Add(key, value);
            }

            Action <System.Xml.XmlNode> decomp = null;

            decomp = (node) =>
            {
                Int16 elementSize = 0;
                reader.Get(ref elementSize);
                for (int i = 0; i < elementSize; i++)
                {
                    Int16 nameKey = -1;
                    reader.Get(ref nameKey);
                    var element = doc.CreateElement(keys[nameKey]);
                    node.AppendChild(element);

                    bool isHaveValue = false;
                    reader.Get(ref isHaveValue);
                    if (isHaveValue)
                    {
                        Int16 value = -1;
                        reader.Get(ref value);
                        var valueNode = doc.CreateNode(System.Xml.XmlNodeType.Text, "", "");
                        valueNode.Value = values[value];
                        element.AppendChild(valueNode);
                    }

                    bool isHaveChildren = false;
                    reader.Get(ref isHaveChildren);
                    if (isHaveChildren)
                    {
                        decomp(element);
                    }
                }
            };


            var declare = doc.CreateXmlDeclaration("1.0", "UTF-8", null);

            doc.AppendChild(declare);
            decomp(doc);

            return(doc);
        }
Example #20
0
        public static string ReplyNews(ReplyNewsModel entity)
        {
            if (null != entity && !string.IsNullOrWhiteSpace(entity.ToUserName) && null != entity.Articles && entity.Articles.list.Count > 0)
            {
                if (entity.Articles.list.Count <= 10)
                {
                    string xmlString = string.Empty;
                    //var s1 = XmlHelper.Serialize(entity);
                    #region xmlString
                    System.Xml.XmlDocument     xmlDoc = new System.Xml.XmlDocument();
                    System.Xml.XmlNode         rootNode;
                    System.Xml.XmlElement      ele;
                    System.Xml.XmlCDataSection cdata;

                    #region xml
                    rootNode = xmlDoc.CreateNode(System.Xml.XmlNodeType.Element, "xml", null);

                    ele   = xmlDoc.CreateElement(nameof(entity.ToUserName));
                    cdata = xmlDoc.CreateCDataSection(entity.ToUserName);
                    ele.AppendChild(cdata);
                    rootNode.AppendChild(ele);

                    ele   = xmlDoc.CreateElement(nameof(entity.FromUserName));
                    cdata = xmlDoc.CreateCDataSection(entity.FromUserName);
                    ele.AppendChild(cdata);
                    rootNode.AppendChild(ele);

                    ele          = xmlDoc.CreateElement(nameof(entity.CreateTime));
                    ele.InnerXml = entity.CreateTime.ToString();
                    rootNode.AppendChild(ele);

                    ele   = xmlDoc.CreateElement(nameof(entity.MsgType));
                    cdata = xmlDoc.CreateCDataSection(entity.MsgType);
                    ele.AppendChild(cdata);
                    rootNode.AppendChild(ele);
                    #endregion

                    ele          = xmlDoc.CreateElement(nameof(entity.ArticleCount));
                    ele.InnerXml = entity.ArticleCount.ToString();
                    rootNode.AppendChild(ele);

                    System.Xml.XmlNode nodeArticles, nodeItem;
                    nodeArticles = xmlDoc.CreateNode(System.Xml.XmlNodeType.Element, nameof(entity.Articles), null);
                    if (entity.ArticleCount > 0)
                    {
                        foreach (var i in entity.Articles.list)
                        {
                            nodeItem = xmlDoc.CreateNode(System.Xml.XmlNodeType.Element, "item", null);

                            ele   = xmlDoc.CreateElement(nameof(i.Title));
                            cdata = xmlDoc.CreateCDataSection(i.Title);
                            ele.AppendChild(cdata);
                            nodeItem.AppendChild(ele);

                            ele   = xmlDoc.CreateElement(nameof(i.Description));
                            cdata = xmlDoc.CreateCDataSection(i.Description);
                            ele.AppendChild(cdata);
                            nodeItem.AppendChild(ele);

                            ele   = xmlDoc.CreateElement(nameof(i.PicUrl));
                            cdata = xmlDoc.CreateCDataSection(i.PicUrl);
                            ele.AppendChild(cdata);
                            nodeItem.AppendChild(ele);

                            ele   = xmlDoc.CreateElement(nameof(i.Url));
                            cdata = xmlDoc.CreateCDataSection(i.Url);
                            ele.AppendChild(cdata);
                            nodeItem.AppendChild(ele);

                            nodeArticles.AppendChild(nodeItem);
                        }
                    }

                    rootNode.AppendChild(nodeArticles);
                    xmlDoc.AppendChild(rootNode);

                    xmlString = xmlDoc.OuterXml;
                    #endregion

                    if (!string.IsNullOrWhiteSpace(xmlString))
                    {
                        return(xmlString);
                    }
                }
                else
                {
                    throw new Exception("如果图文数超过10,则将会无响应。详情情参考微信官方文档");
                }
            }
            return(ReplyEmpty());
        }
                    public override void SaveDB(string filename, DataBase tDataBase)
                    {
                        //tDataBase.WriteXml(filename)

                        System.Xml.XmlDocument XMLDOC = new System.Xml.XmlDocument();
                        XMLDOC.LoadXml("<data></data>");

                        XmlAttribute attr;

                        XmlNode newTable;
                        XmlNode newRow;
                        XmlNode newColumn;

                        foreach (BlackLight.Services.DB.Table tTable in tDataBase)
                        {
                            newTable = XMLDOC.CreateNode(XmlNodeType.Element, "table", "");
                            XMLDOC.DocumentElement.AppendChild(newTable);

                            attr = XMLDOC.CreateAttribute("name");
                            attr.Value = tTable.Name;
                            newTable.Attributes.Append(attr);

                            attr = XMLDOC.CreateAttribute("columns");
                            attr.Value = Convert.ToString(tTable.Columns.Count);
                            newTable.Attributes.Append(attr);

                            attr = XMLDOC.CreateAttribute("primary");
                            attr.Value = tTable.PrimaryColumn;
                            newTable.Attributes.Append(attr);

                            foreach (BlackLight.Services.DB.Column tColumn in tTable.Columns)
                            {
                                newColumn = XMLDOC.CreateNode(XmlNodeType.Element, "column", "");
                                newTable.AppendChild(newColumn);

                                attr = XMLDOC.CreateAttribute("name");
                                attr.Value = tColumn.Name;
                                newColumn.Attributes.Append(attr);

                                attr = XMLDOC.CreateAttribute("type");
                                attr.Value = Convert.ToString(tColumn.DType);
                                newColumn.Attributes.Append(attr);

                            }

                            foreach (BlackLight.Services.DB.Row tRow in tTable)
                            {
                                newRow = XMLDOC.CreateNode(XmlNodeType.Element, "row", "");
                                newTable.AppendChild(newRow);
                                foreach (BlackLight.Services.DB.Column tColumn in tTable.Columns)
                                {
                                    attr = XMLDOC.CreateAttribute(tColumn.Name);
                                    attr.Value = System.Convert.ToString(tRow[tColumn.Name]);
                                    newRow.Attributes.Append(attr);

                                }
                            }

                        }

                        if (System.IO.Directory.Exists("data") == false)
                        {
                            System.IO.Directory.CreateDirectory("data");
                        }

                        XMLDOC.Save("data\\" + filename);
                    }