示例#1
0
        public void SetConfigValue(string strNode, string strAttribute, string newValue)
        {
            try
            {
                //根据指定路径获取节点
                XmlNode xmlNode = _xmlDoc.SelectSingleNode(strNode);

                //获取节点的属性,并循环取出需要的属性值
                XmlAttributeCollection xmlAttr = xmlNode.Attributes;
                for (int i = 0; i < xmlAttr.Count; i++)
                {
                    if (xmlAttr.Item(i).Name.ToUpper() == strAttribute.ToUpper())
                    {
                        xmlAttr.Item(i).Value = newValue;
                    }
                    break;
                }
                //				//如果指定的属性不存在,新建
                //				System.Xml.XmlAttribute attr = new XmlAttribute();
                //				attr.InnerText = strAttribute +"="+newValue;
                //				xmlNode.Attributes.Append(attr);
                SaveConfig();//保存
            }
            catch (XmlException xmle)
            {
                throw xmle;
            }
        }
        public List <Link> ReadCloudConnections()
        {
            List <Link> result = new List <Link>();
            XmlDocument XmlDoc = new XmlDocument();

            try
            {
                XmlDoc.Load("Links.xml");
                Console.WriteLine("Links.xml załadowany!");
                int count = XmlDoc.GetElementsByTagName("Link").Count;
                for (int i = 0; i < count; i++)
                {
                    XmlAttributeCollection coll = XmlDoc.GetElementsByTagName("Link").Item(i).Attributes;
                    Link readLink = new Link(
                        Int32.Parse(XmlDoc.GetElementsByTagName("Link").Item(i).InnerText), // linkId
                        coll.Item(0).InnerText,                                             //firstObjectId
                        coll.Item(2).InnerText,                                             // secondObjectId
                        Int32.Parse(coll.Item(1).InnerText),                                //firstObjectPort
                        Int32.Parse(coll.Item(3).InnerText),                                //secondObjectPort
                        Int32.Parse(coll.Item(4).InnerText)                                 //length <-----trzeba dodac dlugosci do XML !
                        );

                    result.Add(readLink);
                }
            }
            catch (XmlException exc)
            {
                Console.WriteLine(exc.Message);
            }

            return(result);
        }
示例#3
0
    protected void Buscarbtn_Click(object sender, EventArgs e)
    {
        doc.Load(Server.MapPath("~/") + "/Trabajador.xml");
        XmlNode node = doc.SelectSingleNode("//trabajador[@DNI='" + DropDownList1.SelectedValue + "']");

        if (node != null)
        {
            XmlAttributeCollection a = node.Attributes;
            NOMBRE.Text   = a.Item(1).Value;
            EDAD.Text     = a.Item(3).Value;
            TELEFONO.Text = a.Item(4).Value;
            NDIA.Text     = node.ChildNodes[0].Attributes.Item(0).Value;
            NMES.Text     = node.ChildNodes[0].Attributes.Item(1).Value;
            NAÑO.Text     = node.ChildNodes[0].Attributes.Item(2).Value;
            IDIA.Text     = node.ChildNodes[1].Attributes.Item(0).Value;
            IMES.Text     = node.ChildNodes[1].Attributes.Item(1).Value;
            IAÑO.Text     = node.ChildNodes[1].Attributes.Item(2).Value;
            //node.ChildNodes[0].InnerText = textBox1.Text;
            //node.ChildNodes[1].InnerText = textBox2.Text;
            //node.ChildNodes[2].InnerText = textBox3.Text;
            //XmlCDataSection notes = doc.CreateCDataSection(textBox4.Text);
            //node.ChildNodes[3].ReplaceChild(notes, node.ChildNodes[3].ChildNodes[0]);
        }
        doc.Save(Server.MapPath("~/") + "/Trabajador.xml");
    }
示例#4
0
        //Получаем данных о трафике пользователя
        public Dictionary <string, object> getUserInfo(string GUID)
        {
            ITrafInspAdmin ti = connect();

            if (ti == null)
            {
                return(null);
            }

            Dictionary <string, object> retValue = new Dictionary <string, object>();

            try
            {
                string      value = ti.GetList(APIListType.itUser, GUID, null, ConfigAttrLevelType.conf_AttrLevelState);
                XmlDocument doc   = new XmlDocument();
                doc.LoadXml(value);
                XmlAttributeCollection node = doc.ChildNodes.Item(1).FirstChild.Attributes;
                for (int i = 0; i < node.Count; i++)
                {
                    retValue.Add(node.Item(i).Name, node.Item(i).Value);
                }
            }
            catch (Exception) { }
            ti = null;
            return(retValue);
        }
示例#5
0
        public RoutingInfo ReadFIB(string FileName, string routerName)
        {
            RoutingInfo result = new RoutingInfo();
            XmlDocument XmlDoc = new XmlDocument();

            try
            {
                XmlDoc.Load(FileName);
                // Console.WriteLine(FileName + " załadowany!");
                XmlNodeList Node = XmlDoc.GetElementsByTagName(routerName);

                int countRouterLabels = Node.Item(0).ChildNodes[0].ChildNodes.Count;
                //Console.WriteLine(count);
                for (int i = 0; i < countRouterLabels; i++)
                {
                    XmlAttributeCollection xmlRouterLabel = Node.Item(0).ChildNodes[0].ChildNodes[i].Attributes;
                    RouterLabel            routerLabel    = new RouterLabel(
                        Int32.Parse(xmlRouterLabel.Item(0).InnerText),
                        Int32.Parse(xmlRouterLabel.Item(1).InnerText),
                        Int32.Parse(xmlRouterLabel.Item(2).InnerText),
                        Int32.Parse(xmlRouterLabel.Item(3).InnerText)
                        );

                    result.routerLabels.Add(routerLabel);
                }
            }
            catch (XmlException exc)
            {
                Console.WriteLine(exc.Message);
            }

            return(result);
        }
示例#6
0
        /// <summary>
        /// Get attribute with this name
        /// </summary>
        /// <param name="attrName">Attribute name to get</param>
        /// <param name="Value">Attribute value</param>
        /// <param name="exists">States if this attribute exists</param>
        /// <returns>true if successful</returns>
        private bool GetAttributeAt(string attrName, out string Value, out bool exists)
        {
            exists = false;
            Value  = string.Empty;
            if (_Node != null)
            {
                XmlAttributeCollection attrList = _Node.Attributes;

                if (attrList != null)
                {
                    for (int i = 0; i < attrList.Count; ++i)
                    {
                        string name = attrList.Item(i).Name;
                        if (attrName == name)
                        {
                            Value  = attrList.Item(i).InnerText;
                            exists = true;
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
        /// <summary>
        /// Convert XML to entity
        /// </summary>
        /// <param name="element">the element of xml node</param>
        /// <param name="entity">the model xml of entity</param>
        /// <returns>xml model entity</returns>
        public XmlDocumentEntity GetXmlDocumentEntity(XmlElement element, XmlDocumentEntity entity)
        {
            entity.Entitys    = new List <XmlDocumentEntity>();
            entity.Nodes      = new Dictionary <string, string>();
            entity.ChildNodes = new Dictionary <string, string>();
            entity.Nodes.Add(element.Name, null);
            //j = number of child nodes
            for (int j = 0; j < element.ChildNodes.Count; j++)
            {
                XmlDocumentEntity en = new XmlDocumentEntity();
                en.Attributes = new Dictionary <string, string>();
                XmlElement xmlElement = (XmlElement)element.ChildNodes[j];
                entity.ChildNodes.Add(element.ChildNodes.Item(j).Name, null);

                if (xmlElement.HasAttributes)
                {
                    XmlAttributeCollection collection = xmlElement.Attributes;
                    if (collection.Count > 0)
                    {
                        //i = number of attributes
                        for (int i = 0; i < collection.Count; i++)
                        {
                            en.Attributes.Add(collection.Item(i).Name, collection.Item(i).Value);
                        }
                    }
                }
                entity.Entitys.Add(GetXmlDocumentEntity((XmlElement)element.ChildNodes[j], en));
            }

            return(entity);
        }
示例#8
0
        public static void SetXmlNodeAttribute(string xmlPath, string strNode, string strAttribute, string value)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(xmlPath);
            try
            {
                //根据指定路径获取节点
                XmlNode xmlNode = xmlDoc.SelectSingleNode(strNode);
                //获取节点的属性,并循环取出需要的属性值
                XmlAttributeCollection xmlAttr = xmlNode.Attributes;

                for (int i = 0; i < xmlAttr.Count; i++)
                {
                    if (xmlAttr.Item(i).Name == strAttribute)
                    {
                        xmlAttr.Item(i).Value = value;
                    }
                }
                xmlDoc.Save(xmlPath);
            }
            catch (XmlException xmle)
            {
                throw xmle;
            }
        }
示例#9
0
        /// <summary>
        /// 功能:
        /// 读取指定节点的指定属性值
        /// </summary>
        /// <param name="strNode">节点名称(相对路径://+节点名称)</param>
        /// <param name="strAttribute">此节点的属性</param>
        /// <returns></returns>
        public string GetXmlNodeValue(string strNode, string strAttribute)
        {
            string strReturn = "";

            try
            {
                //根据指定路径获取节点
                XmlNode xmlNode = xmlDoc.SelectSingleNode(strNode);
                //获取节点的属性,并循环取出需要的属性值
                XmlAttributeCollection xmlAttr = xmlNode.Attributes;

                for (int i = 0; i < xmlAttr.Count; i++)
                {
                    if (xmlAttr.Item(i).Name == strAttribute)
                    {
                        strReturn = xmlAttr.Item(i).Value;
                    }
                }
            }
            catch (XmlException xmle)
            {
                throw xmle;
            }
            return(strReturn);
        }
示例#10
0
        public static void ParseConfig(string rcName, List <RCContact> contacts, out Graph graph)
        {
            List <RCContact> result = new List <RCContact>();
            XmlDocument      XmlDoc = new XmlDocument();
            List <Edge>      edges  = new List <Edge>();

            try
            {
                XmlDoc.Load("RCinfo.xml");
                Console.WriteLine("RCinfo.xml załadowany!");
                var allRCConfig = XmlDoc.GetElementsByTagName("RC");
                int count       = XmlDoc.GetElementsByTagName("RC").Count;
                int index       = 0;
                for (int i = 0; i < count; i++)
                {
                    if (String.Equals(allRCConfig.Item(i).Attributes.Item(0).InnerText, rcName))
                    {
                        index = i;
                    }
                }
                var thisRcConfig = allRCConfig.Item(index);
                var rcContacts   = thisRcConfig.ChildNodes.Item(0).ChildNodes;
                var rcLinks      = thisRcConfig.ChildNodes.Item(1).ChildNodes;

                for (int i = 0; i < rcContacts.Count; i++)
                {
                    XmlAttributeCollection col1 = rcContacts.Item(i).Attributes;
                    contacts.Add(new RCContact(
                                     col1.Item(0).InnerText,
                                     col1.Item(1).InnerText
                                     ));
                }

                for (int i = 0; i < rcLinks.Count; i++)
                {
                    XmlAttributeCollection col2 = rcLinks.Item(i).Attributes;
                    Edge e = new Edge(
                        Int32.Parse(rcLinks.Item(i).InnerText),
                        col2.Item(0).InnerText,
                        col2.Item(1).InnerText,
                        Int32.Parse(col2.Item(2).InnerText)
                        );
                    if (Boolean.Parse(col2.Item(3).InnerText))
                    {
                        e.isDirect  = true;
                        e.startPort = Int32.Parse(col2.Item(4).InnerText);
                        e.endPort   = Int32.Parse(col2.Item(5).InnerText);
                    }
                    edges.Add(e);
                }
            }
            catch (XmlException exc)
            {
                Console.WriteLine(exc.Message);
            }
            graph = new Graph(edges);
        }
示例#11
0
        public static void CopyXmlAttrs(XmlElement fromNode, XmlElement toNode)
        {
            XmlAttributeCollection atrs = fromNode.Attributes;

            for (int i = 0; i < atrs.Count; i++)
            {
                toNode.SetAttribute(atrs.Item(i).Name, atrs.Item(i).Value);
            }
        }
示例#12
0
 /// <summary>
 /// 找到指定名称属性的值
 /// </summary>
 /// <param name="xac"></param>
 /// <param name="strName"></param>
 /// <returns></returns>
 protected string GetXaValue(XmlAttributeCollection xac, string strName)
 {
     for (int i = 0; i < xac.Count; i++)
     {
         if (xac.Item(i).LocalName == strName)
         {
             return(xac.Item(i).Value);
         }
     }
     return(null);
 }
示例#13
0
 /// <summary>
 /// 为一个属性指定值
 /// </summary>
 /// <param name="xac"></param>
 /// <param name="strName"></param>
 /// <param name="strValue"></param>
 protected void SetXaValue(XmlAttributeCollection xac, string strName, string strValue)
 {
     for (int i = 0; i < xac.Count; i++)
     {
         if (xac.Item(i).LocalName == strName)
         {
             xac.Item(i).Value = strValue;
             return;
         }
     }
     return;
 }
示例#14
0
        public BitmapFont(Texture2D texture, string pathXML)
        {
            sprites            = new Dictionary <string, Sprite>();
            yoffsets_xadvances = new Dictionary <string, Vector2>();
            rects = new Dictionary <string, Rect>();

            float     heightTexture = texture.height;
            TextAsset xml           = Resources.Load <TextAsset>(pathXML);

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(new StringReader(xml.text));

            foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes)
            {
                XmlAttributeCollection collection = node.Attributes;
                Rect rect = new Rect(
                    float.Parse(collection.Item(0).Value),                                                         //left
                    heightTexture - float.Parse(collection.Item(1).Value) - float.Parse(collection.Item(3).Value), //top
                    float.Parse(collection.Item(2).Value),                                                         //width
                    float.Parse(collection.Item(3).Value));                                                        //height

                rects.Add(collection.Item(6).Value, rect);                                                         //rects

                sprites.Add(collection.Item(6).Value, Sprite.Create(texture, rect, Vector2.zero));                 //sprites

                //yoffset and xadvance
                yoffsets_xadvances.Add(collection.Item(6).Value,
                                       new Vector2(float.Parse(collection.Item(4).Value), float.Parse(collection.Item(5).Value)));
            }
        }
示例#15
0
        /// <summary>
        /// Gets the attribute value.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="attr">The attr.</param>
        /// <returns></returns>
        public string GetAttributeValue(XmlNode node, string attr)
        {
            string output = null;
            XmlAttributeCollection attrColl = node.Attributes;

            for (int i = 0; i < attrColl.Count; i++)
            {
                if (attrColl.Item(i).Name.Equals(attr))
                {
                    output = attrColl.Item(i).Value;
                }
            }
            return(output);
        }
示例#16
0
        private void readLinks()
        {
            //odczyt z XML
            XmlDocument XmlDoc = new XmlDocument();

            try
            {
                XmlDoc.Load(System.Configuration.ConfigurationManager.AppSettings["connections"]);
                Console.WriteLine("Dokument załadowany!");
                int count = XmlDoc.GetElementsByTagName("Link").Count;
                for (int i = 0; i < count; i++)
                {
                    Link tempLink1 = new Link();
                    XmlAttributeCollection coll = XmlDoc.GetElementsByTagName("Link").Item(i).Attributes;
                    tempLink1.sourceId     = coll.Item(0).InnerText;
                    tempLink1.sourcePort   = Int32.Parse(coll.Item(1).InnerText);
                    tempLink1.receiverId   = coll.Item(2).InnerText;
                    tempLink1.receiverPort = Int32.Parse(coll.Item(3).InnerText);
                    linkList.Add(tempLink1);
                }
            }
            catch (XmlException exc)
            {
                Console.WriteLine(exc.Message);
            }

            ListViewItem[] listViewList = new ListViewItem[linkList.Count];
            listView1.View      = View.Details;
            listView1.GridLines = true;
            listView1.Columns.Add("Link ID");
            listView1.Columns.Add("Source ID");
            listView1.Columns.Add("Source Port");
            listView1.Columns.Add("Receiver ID");
            listView1.Columns.Add("Receiver Port");

            for (int i = 0; i < linkList.Count; i++)
            {
                Console.WriteLine(linkList[i].sourceId + " " + linkList[i].sourcePort
                                  + " " + linkList[i].receiverId + " " + linkList[i].receiverPort);

                ListViewItem tempItem = new ListViewItem((i + 1).ToString());
                tempItem.SubItems.Add(linkList[i].sourceId);
                tempItem.SubItems.Add(linkList[i].sourcePort.ToString());
                tempItem.SubItems.Add(linkList[i].receiverId);
                tempItem.SubItems.Add(linkList[i].receiverPort.ToString());
                listViewList[i] = tempItem;
            }
            listView1.Items.AddRange(listViewList);
        }
示例#17
0
        public static EmptyElement readXml(XmlNode emptyElt)
        {
            EmptyElement ee = null;

            if (emptyElt == null)
            {
                return(ee);
            }
            if (emptyElt.HasChildNodes)
            {             // this is not empty!
                Log log = Log.getOnly();
                log.writeElt("fail");
                log.writeAttr("node", emptyElt.Name);
                log.writeAttr("expected", "empty");
                log.endElt();
            }
            else             // this is a truly empty node
            {
                ee = new EmptyElement(emptyElt.Name);
                XmlAttributeCollection attrs = emptyElt.Attributes;
                for (int a = 0; a < attrs.Count; a++)
                {                 // read all attributes
                    XmlNode attr = attrs.Item(a);
                    ee.addAttribute(attr.Name, attr.Value);
                }
            }
            return(ee);
        }
示例#18
0
    public static void Main()
    {
        XmlDocument doc = new XmlDocument();

        doc.LoadXml("<book genre='novel' publicationdate='1997'> " +
                    "  <title>Pride And Prejudice</title>" +
                    "</book>");

        XmlAttributeCollection attrColl = doc.DocumentElement.Attributes;

        Console.WriteLine("Display all the attributes for this book...");
        for (int i = 0; i < attrColl.Count; i++)
        {
            Console.WriteLine("{0} = {1}", attrColl.Item(i).Name, attrColl.Item(i).Value);
        }
    }
示例#19
0
        /// <summary>
        /// Object callback
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void YTplayer_FlashCall(object sender, AxShockwaveFlashObjects._IShockwaveFlashEvents_FlashCallEvent e)
        {
            // message is in xml format so we need to parse it
            XmlDocument document = new XmlDocument();

            document.LoadXml(e.request);
            // get attributes to see which command flash is trying to call
            XmlAttributeCollection attributes = document.FirstChild.Attributes;
            String command = attributes.Item(0).InnerText;
            // get parameters
            XmlNodeList list = document.GetElementsByTagName("arguments");

            List <string> listS = (from XmlNode l in list select l.InnerText).ToList();

            // Interpret command
            switch (command)
            {
            case "onYouTubePlayerReady": YTready(listS[0]); break;

            case "YTStateChange": YTStateChange(listS[0]); break;

            case "YTError": YTStateError(listS[0]); break;

            case "document.location.href.toString": YTplayer.SetReturnValue("<string>http://www.youtube.com/watch?v=" + currentlyPlayingVideoId + "</string>"); break;

            default: Console.Write("YTplayer_FlashCall: (unknownCommand)\r\n"); break;
            }
        }
示例#20
0
        //----------------------------------------------------------------------------------------
        // Выбор инструмента из списка
        private void lstTools_Click(object sender, EventArgs e)
        {
            // Получили название инструмента
            string sItemName = lstTools.GetItemText(lstTools.SelectedItem);

            // Получили название класса инструмента
            // Загружаем из файл-шаблона названия инструмента, заполняя форму.
            XmlDocument xDoc = new XmlDocument();

            xDoc.Load(Connect.assemblyFolder + StringResource.xmlPathToolsParams);
            XmlElement xRoot = xDoc.DocumentElement;

            // выбор всех инструментов "user[@name='Bill Gates']"
            XmlNode childNode = xRoot.SelectSingleNode(
                StringResource.xmlElementName + "[@" +
                StringResource.xmlToolLabel + "='" + sItemName + "']");

            XmlAttributeCollection xmlCollection = childNode.Attributes;
            string sClassName = xmlCollection.Item(0).Value;

            //fillFrmList(sClassName);
            fillFrmParametersList(sClassName);

            listEspGostParams.Items.Clear();
            fillFrmReportList(sClassName);

            Console.WriteLine("test");
        }
示例#21
0
        private static XmlNodeList SelectAllAttributes(XmlNode parentNode)
        {
            XmlAttributeCollection attributes = parentNode.Attributes;

            if (attributes.Count == 0)
            {
                OnNoMatchingNode("@*");
                return(null);
            }
            else if (attributes.Count == 1)
            {
                XmlPatchNodeList nodeList = new SingleNodeList();
                nodeList.AddNode(attributes.Item(0));
                return(nodeList);
            }
            else
            {
                IEnumerator      enumerator = attributes.GetEnumerator();
                XmlPatchNodeList nodeList   = new MultiNodeList();
                while (enumerator.MoveNext())
                {
                    nodeList.AddNode((XmlNode)enumerator.Current);
                }
                return(nodeList);
            }
        }
        protected override void ParseTransformer(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder)
        {
            ManagedDictionary      headers    = new ManagedDictionary();
            XmlAttributeCollection attributes = element.Attributes;

            for (int i = 0; i < attributes.Count; i++)
            {
                XmlNode node = attributes.Item(i);
                String  name = node.LocalName;
                if (IsEligibleHeaderName(name))
                {
                    name = Conventions.AttributeNameToPropertyName(name);
                    object value;
                    if (ReferenceAttributesContains(name))
                    {
                        value = new RuntimeObjectReference(node.Value);
                    }
                    else
                    {
                        value = node.Value;
                    }

                    if (_prefix != null)
                    {
                        name = _prefix + name;
                    }
                    headers.Add(name, value);
                }
            }
            PostProcessHeaders(element, headers, parserContext);
            builder.AddConstructorArg(headers);
            builder.AddPropertyValue("overwrite", ShouldOverwrite(element));
        }
示例#23
0
文件: XMLHelper.cs 项目: sxf359/sxf
        /// <summary>
        /// 获取指定节点的属性
        /// </summary>
        /// <param name="NodeIndex">节点索引</param>
        /// <param name="strNodePath">节点路径</param>
        /// <param name="AttributeIndex">属性索引</param>
        /// <returns>属性值</returns>
        public string GetXmlNodeAttribute(int NodeIndex, string strNodePath, int AttributeIndex)
        {
            string strReturn = "";

            try
            {
                if (NodeIndex != -1)
                {
                    //根据指定路径获取节点列表
                    XmlNodeList ndlist = xmlDoc.SelectNodes(strNodePath);
                    //获取指定节点属性
                    XmlAttributeCollection xmlAttr = ndlist[NodeIndex].Attributes;
                    //获取节点属性列表中的指定的属性值
                    strReturn = xmlAttr.Item(AttributeIndex).Value;
                }
                else
                {
                    //根据指定路径获取节点
                    XmlNode xmlNode = xmlDoc.SelectSingleNode(strNodePath);
                    //获取节点的属性
                    XmlAttributeCollection xmlAttr = xmlNode.Attributes;
                    //获取节点属性列表中的指定属性名称的属性值
                    strReturn = xmlAttr.Item(AttributeIndex).Value;
                }
            }
            catch (XmlException xmle)
            {
                throw xmle;
            }
            return(strReturn);
        }
示例#24
0
        private void player_Call(object sender, _IShockwaveFlashEvents_FlashCallEvent e)
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(e.request);
            XmlAttributeCollection attributes = xmlDocument.FirstChild.Attributes;
            string      innerText             = attributes.Item(0).InnerText;
            XmlNodeList elementsByTagName     = xmlDocument.GetElementsByTagName("arguments");
            string      a;

            if ((a = innerText) != null)
            {
                if (!(a == "sendText"))
                {
                    if (!(a == "Some_Other_Command"))
                    {
                        return;
                    }
                }
                else if (elementsByTagName[0].InnerText == "ChangeText" && this.isGenerate)
                {
                    this.StopCount++;
                    if (this.StopCount == this.PageCount)
                    {
                        this.Event(AnimationEventType.Stop);
                    }
                }
            }
        }
示例#25
0
        /// <summary>
        /// Process the parameters of a Sequence. If a parameter of the same name is found in the list of parameters
        /// it overrides the XML parameter of the sequence
        /// </summary>
        /// <param name="seqParam">List of parameters</param>
        /// <param name="xmlSeqParam">Parameters of the XML sequence</param>
        /// <returns>The list of parameters to used to process the sequence of APDU commands</returns>
        private SequenceParameter ProcessParams(SequenceParameter seqParam, XmlAttributeCollection xmlSeqParam)
        {
            //Dictionary<string, string> l_seqParam = new Dictionary<string, string>();
            SequenceParameter l_seqParam = new SequenceParameter();

            int nNbParam = xmlSeqParam.Count;

            for (int nI = 0; nI < nNbParam; nI++)
            {
                XmlNode xNode = xmlSeqParam.Item(nI);

                string name = xNode.Name;
                string val  = xNode.Value;

                // Check if a val overrides the XML parameter of Sequence
                if (seqParam != null)
                {
                    try
                    {
                        val = seqParam[name];
                    }
                    catch
                    {
                    }
                }

                l_seqParam.Add(name, val);
            }

            return(l_seqParam);
        }
示例#26
0
    /// <summary>
    /// 解析xml配置并放入Dictionary中
    /// </summary>
    /// <param name="xmlFilePath">文件路径 + 文件名称</param>
    /// <param name="rootNodeName">根节点名字</param>
    /// <param name="fieldname">做完key保存使用的字段名</param>
    /// <returns序列化后的存放数据的Dictionary></returns>
    public static Dictionary <String, T> parse <T>(String xmlFilePath, String rootNodeName, String fieldname)
    {
        XmlReaderSettings settings = new XmlReaderSettings();

        //忽略注释
        settings.IgnoreComments = true;
        XmlReader   reader = XmlReader.Create(xmlFilePath, settings);
        XmlDocument doc    = new XmlDocument();

        doc.Load(reader);
        //节点列表
        XmlNodeList nodeList = doc.SelectNodes(rootNodeName);

        if (nodeList == null)
        {
            return(null);
        }
        //创建列表
        Dictionary <String, T> dict = new Dictionary <String, T>();
        List <String>          attributesNameList = new List <String>();
        XmlNodeList            childNodeList      = nodeList.Item(0).ChildNodes;
        XmlNode firstNode = childNodeList.Item(0);
        XmlAttributeCollection attributes = firstNode.Attributes;
        int count = attributes.Count;

        //遍历属性名称放入list
        for (int i = 0; i < count; ++i)
        {
            attributesNameList.Add(attributes.Item(i).Name);
        }
        //遍历整个xml
        foreach (XmlNode node in childNodeList)
        {
            //new 这个泛型
            T      s   = System.Activator.CreateInstance <T>();
            String key = null;
            for (int i = 0; i < count; ++i)
            {
                //获取属性名称
                String name = attributesNameList[i];
                if (name == fieldname)
                {
                    key = node.Attributes[name].Value;
                }
                //根据字段名称设置某个对象内部的值
                XMLUtil.setObjectValue <T>(s, name, node.Attributes[name].Value);
            }
            try
            {
                //根据字段名称取到的值作为key 保存vo对象
                dict.Add(key, s);
            }
            catch
            {
                throw new ArgumentException("找不到key");
            }
        }
        return(dict);
    }
示例#27
0
        /// <summary>
        /// 根据key的值,获取相应节点的value值
        /// </summary>
        /// <param name="strNode">节点</param>
        /// <param name="key">key值</param>
        /// <returns></returns>
        public string GetXmlKeyValue(string strNode, string key)
        {
            XmlDocument xmlDoc = new XmlDocument();

            if (!string.IsNullOrEmpty(this.fileContent))
            {
                xmlDoc.LoadXml(this.fileContent);
            }
            else
            {
                xmlDoc.Load(this.filePath);
            }
            string strReturn = "";

            try
            {
                //根据指定路径获取节点列表
                XmlNodeList xmlNodeList = xmlDoc.SelectNodes(strNode);
                foreach (XmlNode xmlNode in xmlNodeList)
                {
                    //获取节点的属性,并循环取出需要的属性值
                    XmlAttributeCollection xmlAttr = xmlNode.Attributes;

                    for (int i = 0; i < xmlAttr.Count; i++)
                    {
                        if (xmlAttr.Item(i).Name.Equals("key", StringComparison.OrdinalIgnoreCase))
                        {
                            if (!xmlAttr.Item(i).Value.Equals(key, StringComparison.OrdinalIgnoreCase))
                            {
                                break;
                            }
                        }
                        if (xmlAttr.Item(i).Name.Equals("value", StringComparison.OrdinalIgnoreCase))
                        {
                            strReturn = xmlAttr.Item(i).Value;
                            return(strReturn);
                        }
                    }
                }
            }
            catch (XmlException xmle)
            {
                throw xmle;
            }
            return(strReturn);
        }
示例#28
0
        private string GetNodeAttrValue(string key, XmlNode xmlNode)
        {
            if (xmlNode == null || xmlNode.Attributes == null)
            {
                return(string.Empty);
            }
            XmlAttributeCollection xmlAttr = xmlNode.Attributes;

            for (int i = 0; i < xmlAttr.Count; i++)
            {
                if (xmlAttr.Item(i).Name.ToUpper() == key.ToUpper())
                {
                    return(xmlAttr.Item(i).Value);
                }
            }
            return(string.Empty);
        }
示例#29
0
        private void SetNodeAttrValue(string key, string value, XmlNode xmlNode)
        {
            XmlAttributeCollection xmlAttr = xmlNode.Attributes;

            for (int i = 0; i < xmlAttr.Count; i++)
            {
                if (xmlAttr.Item(i).Name.ToUpper() == key.ToUpper())
                {
                    xmlAttr.Item(i).Value = value;
                    return;
                }
            }
            //can't find so add here
            XmlAttribute nodeAttribute = xmlNode.OwnerDocument.CreateAttribute(key);

            nodeAttribute.Value = value;
            xmlNode.Attributes.Append(nodeAttribute);
        }
示例#30
0
            public void Add(ItemType type, XmlAttributeCollection nodes)
            {
                Item item = GetItem(type);

                for (int k = 0; k < nodes.Count; k++)
                {
                    item.nodes.Add(nodes.Item(k));
                }
            }