Example #1
0
        public static void GetAttributesOnTextNode()
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml("<a>text node</a>");

            Assert.Null(xmlDocument.DocumentElement.FirstChild.Attributes);
        }
    static void Main()
    {
        XmlDocument doc = new XmlDocument();
        doc.Load(@"..\..\..\catalogue.xml");
        XmlNode rootNode = doc.DocumentElement;

        for (int i = 0; i < rootNode.ChildNodes.Count; i++)
        {
            XmlNode node = rootNode.ChildNodes[i];

            foreach (XmlNode albumPrice in node.ChildNodes)
            {
                // if the node is the price node
                if (albumPrice.Name == "price")
                {
                    // take the price
                    double price = double.Parse(albumPrice.InnerText);
                    if (price > 20.00)
                    {
                        rootNode.RemoveChild(node); // remove the node
                        i--; // decrementing i so that we won't miss a node
                    }
                }
            }
        }

        doc.Save(@"..\..\..\catalogueUnderTwentyPrice.xml");
    }
    public void SetAppTypeProduct()
    {
        try
        {
            XmlDocument doc = new XmlDocument();
            string xpath = Server.MapPath("../data/xml/configproduct.xml");
            XmlTextReader reader = new XmlTextReader(xpath);
            doc.Load(reader);
            reader.Close();
            XmlNodeList nodes = doc.SelectNodes("/root/product");
            int numnodes = nodes.Count;
            for (int i = 0; i < numnodes; i++)
            {
                string nameapp = nodes.Item(i).ChildNodes[0].InnerText;
                string idtype = nodes.Item(i).ChildNodes[1].InnerText;
                string appunit = nodes.Item(i).ChildNodes[2].InnerText;
                string unit = nodes.Item(i).ChildNodes[3].InnerText;
                if (nameapp.Length > 0 && idtype.Length > 0)
                {
                    Application[nameapp] = int.Parse(idtype);
                }
                if (appunit.Length > 0 && unit.Length > 0)
                {
                    Application[appunit] = unit;
                }
            }
        }
        catch
        {

        }
    }
Example #4
0
        public static void DocumentNodeTypeTest()
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml("<a />");

            Assert.Equal(XmlNodeType.Document, xmlDocument.NodeType);
        }
    private void GetUpdateList(string updateKey)
    {
        WebClient client = new WebClient();
        client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";

        string response;

        try
        {
            response = client.UploadString("http://infinity-code.com/products_update/checkupdates.php",
            "k=" + WWW.EscapeURL(updateKey) + "&v=" + OnlineMaps.version + "&c=" + (int)channel);
        }
        catch
        {
            return;
        }
        
        XmlDocument document = new XmlDocument();
        document.LoadXml(response);

        XmlNode firstChild = document.FirstChild;
        updates = new List<OnlineMapsUpdateItem>();

        foreach (XmlNode node in firstChild.ChildNodes) updates.Add(new OnlineMapsUpdateItem(node));
    }
Example #6
0
    public static void SetCountriesName(string language)
    {
        Debug.Log("countries....." +  language);
        TextAsset textAsset = (TextAsset) Resources.Load("countries");
        var xml = new XmlDocument ();
        xml.LoadXml (textAsset.text);

        Countries = new Hashtable();
        AppCountries = new SortedList();

        try{
            var element = xml.DocumentElement[language];
            if (element != null) {
                var elemEnum = element.GetEnumerator();
                while (elemEnum.MoveNext()) {
                    var xmlItem = (XmlElement)elemEnum.Current;
                    Countries.Add(xmlItem.GetAttribute("name"), xmlItem.InnerText);
                    AppCountries.Add(xmlItem.GetAttribute("name"), xmlItem.InnerText);
                }
            } else {
                Debug.LogError("The specified language does not exist: " + language);
            }

        }
        catch (Exception ex)
        {
            Debug.Log("Language:SetCountryName()" + ex.ToString());
        }
    }
Example #7
0
    public void GetData()
    {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(LevelStats.text);

        StartCoroutine(LoadLevelStats(xmlDoc));
    }
Example #8
0
	public void TestOASIS ()
	{
		XmlDocument doc = new XmlDocument ();
		doc.NodeInserting += new XmlNodeChangedEventHandler (OnInserting);
		doc.NodeInserted += new XmlNodeChangedEventHandler (OnInserted);
		doc.NodeChanging += new XmlNodeChangedEventHandler (OnChanging);
		doc.NodeChanged += new XmlNodeChangedEventHandler (OnChanged);
		doc.NodeRemoving += new XmlNodeChangedEventHandler (OnRemoving);
		doc.NodeRemoved += new XmlNodeChangedEventHandler (OnRemoved);

		foreach (FileInfo fi in
			new DirectoryInfo (@"xml-test-suite/xmlconf/oasis").GetFiles ("*.xml")) {
			try {
				if (fi.Name.IndexOf ("fail") >= 0)
					continue;

				Console.WriteLine ("#### File: " + fi.Name);

				XmlTextReader xtr = new XmlTextReader (fi.FullName);
				xtr.Namespaces = false;
				xtr.Normalization = true;
				doc.RemoveAll ();
				doc.Load (xtr);

			} catch (XmlException ex) {
				if (fi.Name.IndexOf ("pass") >= 0)
					Console.WriteLine ("Incorrectly invalid: " + fi.FullName + "\n" + ex.Message);
			}
		}
	}
    public void Adjust(string fileName)
    {
        try
        {
            string path = Path.GetDirectoryName(Application.dataPath+"..");
            if (File.Exists(path+"/"+fileName))
            {
                TextReader tx = new StreamReader(path+"/"+fileName);
                if (doc == null)
                    doc = new XmlDocument();
                doc.Load(tx);
                tx.Close();
                if (doc!=null && doc.DocumentElement!=null)
                {
                    string xmlns = doc.DocumentElement.Attributes["xmlns"].Value;
                    XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                    nsmgr.AddNamespace("N",xmlns);

                    SetNode("TargetFrameworkVersion","v4.0", nsmgr);
                    // SetNode("DefineConstants","TRACE;UNITY_3_5_6;UNITY_3_5;UNITY_EDITOR;ENABLE_PROFILER;UNITY_STANDALONE_WIN;ENABLE_GENERICS;ENABLE_DUCK_TYPING;ENABLE_TERRAIN;ENABLE_MOVIES;ENABLE_WEBCAM;ENABLE_MICROPHONE;ENABLE_NETWORK;ENABLE_CLOTH;ENABLE_WWW;ENABLE_SUBSTANCE", nsmgr);

                    TextWriter txs = new StreamWriter(path+"/"+fileName);
                    doc.Save(txs);
                    txs.Close();
                }
            }
        }
        catch(System.Exception)
        {
        }
    }
    static void Main()
    {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load("../../catalogue.xml");
        string xPathQuery = "/catalog/album";

        XmlNodeList ArtistsList = xmlDoc.SelectNodes(xPathQuery);
        Dictionary<string, int> artistsAndAlbumsCount = new Dictionary<string, int>();

        foreach (XmlNode ArtistNode in ArtistsList)
        {
            string authorName = ArtistNode.SelectSingleNode("artist").InnerText;
            if (artistsAndAlbumsCount.ContainsKey(authorName))
            {
                artistsAndAlbumsCount[authorName]++;
            }
            else
            {
                artistsAndAlbumsCount.Add(authorName, 1);
            }
        }

        foreach (var artist in artistsAndAlbumsCount)
        {
            Console.WriteLine("Artist: {0}", artist.Key);
            Console.WriteLine("Albums count: {0}", artist.Value);
            Console.WriteLine();
        }
    }
Example #11
0
    /// <summary>
    /// 删除XmlNode属性
    /// 使用示列:
    /// XmlHelper.DeleteAttribute(path, nodeName, "");
    /// XmlHelper.DeleteAttribute(path, nodeName, attributeName,attributeValue);
    /// </summary>
    /// <param name="path">文件路径</param>
    /// <param name="nodeName">节点名称</param>
    /// <param name="attributeName">属性名称</param>
    /// <returns>void</returns>
    public static void DeleteAttribute(string path, string nodeName, string attributeName)
    {
        if (attributeName.Equals(""))
        {
            return;
        }

        try
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(path);

            XmlElement element = doc.SelectSingleNode(nodeName) as XmlElement;
            if (element == null)
            {
                throw new Exception("节点元素不存在!");
            }
            else
            {
                element.RemoveAttribute(attributeName);
                doc.Save(path);
            }
        }
        catch
        { }
    }
Example #12
0
    public static void WriteToXml(string namePlayer)
    {
        string filepath = Application.dataPath + @"/Data/hightScores.xml";
        XmlDocument xmlDoc = new XmlDocument();

        if (File.Exists(filepath))
        {
            xmlDoc.Load(filepath);

            XmlElement elmRoot = xmlDoc.DocumentElement;

           // elmRoot.RemoveAll(); // remove all inside the transforms node.

            XmlElement scoresHelper = xmlDoc.CreateElement("allScores"); // create the rotation node.

            XmlElement name = xmlDoc.CreateElement("name"); // create the x node.
            name.InnerText = namePlayer; // apply to the node text the values of the variable.

            XmlElement score = xmlDoc.CreateElement("score"); // create the x node.
            score.InnerText = "" + Game.points; // apply to the node text the values of the variable.

            scoresHelper.AppendChild(name); // make the rotation node the parent.
            scoresHelper.AppendChild(score); // make the rotation node the parent.

            elmRoot.AppendChild(scoresHelper); // make the transform node the parent.

            xmlDoc.Save(filepath); // save file.
        }
    }
Example #13
0
        public static void GetAttributesOnDocumentFragment()
        {
            var xmlDocument = new XmlDocument();
            var documentFragment = xmlDocument.CreateDocumentFragment();

            Assert.Null(documentFragment.Attributes);
        }
Example #14
0
        public static void GetAttributesOnCDataNode()
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml("<a><![CDATA[test data]]></a>");

            Assert.Null(xmlDocument.DocumentElement.FirstChild.Attributes);
        }
Example #15
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //Load document
        string booksFile = Server.MapPath("books.xml");

        XmlDocument document = new XmlDocument();
        document.Load(booksFile);
        XPathNavigator nav = document.CreateNavigator();

        //Add a namespace prefix that can be used in the XPath expression
        XmlNamespaceManager namespaceMgr = new XmlNamespaceManager(nav.NameTable);
        namespaceMgr.AddNamespace("b", "http://example.books.com");

        //All books whose price is not greater than 10.00
        foreach (XPathNavigator node in
            nav.Select("//b:book[not(b:price[. > 10.00])]/b:price",
            namespaceMgr))
        {
            Decimal price = (decimal)node.ValueAs(typeof(decimal));
            node.SetTypedValue(price * 1.2M);
            Response.Write(String.Format("Price raised from {0} to {1}<BR/>",
                price,
                node.ValueAs(typeof(decimal))));
        }
    }
 public void initialiseSpellButtons(XmlDocument xmlDoc)
 {
     XmlNodeList spellList = xmlDoc.GetElementsByTagName("spells")[0].ChildNodes;
     for(int i = 0; i < spellButtons.Length; i++) {
         CmdSpawn(i, spellList[i].LastChild.InnerText);
     }
 }
Example #17
0
    public void MakeList()
    {
        XmlDocument xmlDoc = new XmlDocument(); // xmlDoc is the new xml document.
        xmlDoc.LoadXml(ELEData.text); // load the file.
        XmlNodeList EleList = xmlDoc.GetElementsByTagName("storeElement"); // array of the level nodes.
        GameObject eleGO;
        StoreElement strElmnt;
        int i = 0;
        foreach (XmlNode eleInfo in EleList)
        {
            int pfI = int.Parse(eleInfo.Attributes["storeType"].Value);
            eleGO = (GameObject)Instantiate(ELEPrefab[pfI]);
            if(pfI==0){
                Text txtEl = eleGO.GetComponent<Text>();
                txtEl.text = LanguageManager.current.getText(eleInfo.Attributes["name"].Value);
            }else if(pfI==1){
                strElmnt = eleGO.GetComponent<StoreElement>();
                int toolIndex = int.Parse(eleInfo.Attributes["imageIndex"].Value);
                strElmnt.init(
                    eleInfo.Attributes["id"].Value,
                    i,
                    LanguageManager.current.getText(eleInfo.Attributes["name"].Value),
                    LanguageManager.current.getSentance(eleInfo.Attributes["desc"].Value,"20"),
                    (ToolType)toolIndex,
                    ElEImages[toolIndex],
                    (eleInfo.Attributes["upgrades"] != null)
                );
                elmentList.Add(strElmnt);
            }

            eleGO.transform.SetParent(gridGroup.transform);
            eleGO.transform.localScale = Vector3.one;

        }
    }
Example #18
0
 /*
 ****************************************************************************
 * dump()
 ****************************************************************************
 */
 /**
 * Returns obj as a formatted XML string.
 * @param sTab - The characters to prepend before each new line
 */
 public string dump()
 {
     XmlDocument doc = new XmlDocument();
     XmlElement elm = this.toDOM(doc);
     doc.AppendChild(elm);
     return DOMUtils.ToString(doc);
 }
Example #19
0
    protected void DL_SubjectArealist_ItemDatabound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            ListViewDataItem ditem = (ListViewDataItem)e.Item;
            //data reader
            System.Data.DataRowView item = (System.Data.DataRowView)ditem.DataItem;
            Literal myfavicons = (Literal)ditem.FindControl("myfavicons");
            HyperLink SubjectAreaTitle = (HyperLink)ditem.FindControl("SubjectAreaTitle");
            Literal Description = (Literal)ditem.FindControl("Description");

            XmlDocument XMLDoc = new XmlDocument();
            XMLDoc.LoadXml(item["content_html"].ToString());

            string ShortDescription = commonfunctions.getFieldValue(XMLDoc, "ShortDescription", "/SubjectAreas");
            string Name = commonfunctions.getFieldValue(XMLDoc, "Name", "/SubjectAreas");

            long saId = long.Parse(item["content_id"].ToString());
            Description.Text = ShortDescription;
            myfavicons.Text = commonfunctions.getMyFavIcons(saId.ToString(), "2", Title, "0");
            SubjectAreaTitle.Text = Name;
            SubjectAreaTitle.NavigateUrl = commonfunctions.getQuickLink(saId); ;

        }
    }
Example #20
0
        public static void CreateCdata()
        {
            var xmlDocument = new XmlDocument();
            var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection("abcde");

            Assert.Equal(5, cdataNode.Length);
        }
Example #21
0
        public static void AttributeNode()
        {
            var xmlDocument = new XmlDocument();
            var node = xmlDocument.CreateAttribute("attribute");

            Assert.Equal(String.Empty, node.Value);
        }
Example #22
0
        public static void CreateEmptyCdata()
        {
            var xmlDocument = new XmlDocument();
            var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection(String.Empty);

            Assert.Equal(0, cdataNode.Length);
        }
Example #23
0
    /*!
    \brief Load all the proprieties from a file
    \param The path of the file
    \return The list of ActiveTranportProprieties. If the list is empty this function return null
       */
    public LinkedList<ActiveTransportProprieties> loadActiveTransportProprietiesFromFile(string filePath)
    {
        LinkedList<ActiveTransportProprieties>      propsList = new LinkedList<ActiveTransportProprieties>();
        ActiveTransportProprieties                  prop;

        MemoryStream ms = Tools.getEncodedFileContent(filePath);
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(ms);

        XmlNodeList ATsLists = xmlDoc.GetElementsByTagName("activeTransports");
        foreach (XmlNode ATsNodes in ATsLists)
          {
        foreach (XmlNode ATNode in ATsNodes)
          {
            if (ATNode.Name == "ATProp")
              {
                prop = loadActiveTransportProprieties(ATNode);
                propsList.AddLast(prop);
              }
          }
          }

        if (propsList.Count == 0)
          return null;
        return propsList;
    }
Example #24
0
        public static void CheckNodeType()
        {
            var xmlDocument = new XmlDocument();
            var documentFragment = xmlDocument.CreateDocumentFragment();

            Assert.Equal(XmlNodeType.DocumentFragment, documentFragment.NodeType);
        }
Example #25
0
    static public string Request_POST(string rooturl, string param)
    {

        HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(rooturl);
        Encoding encoding = Encoding.UTF8;
        byte[] bs = Encoding.ASCII.GetBytes(param);
        string responseData = String.Empty;
        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";
        req.ContentLength = bs.Length;
        using (Stream reqStream = req.GetRequestStream())
        {
            reqStream.Write(bs, 0, bs.Length);
            reqStream.Close();
        }
        using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
        {
            using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
            {
                responseData = reader.ReadToEnd().ToString();
            }
            
        }

        XmlDocument doc = new XmlDocument();
        doc.LoadXml(responseData);
        XmlElement root = doc.DocumentElement;
        return root.InnerText;

    }
Example #26
0
    protected void DL_newslist_ItemDatabound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            ListViewDataItem ditem = (ListViewDataItem)e.Item;
            //data reader
            System.Data.DataRowView item = (System.Data.DataRowView)ditem.DataItem;

            HyperLink NewsTitle = (HyperLink)ditem.FindControl("NewsTitle");
            Literal NewsDate = (Literal)ditem.FindControl("NewsDate");

            XmlDocument XMLDoc = new XmlDocument();
            XMLDoc.LoadXml(item["content_html"].ToString());

            string HeadLine = commonfunctions.getFieldValue(XMLDoc, "Headline", "/News");
            string Date = commonfunctions.getFieldValue(XMLDoc, "Date", "/News");
            string Teaser = commonfunctions.getFieldValue(XMLDoc, "Teaser", "/News");

            DateTime DateShown = Convert.ToDateTime(Date);
            long newsId = long.Parse(item["content_id"].ToString());
            NewsDate.Text = DateShown.ToString("MMMM dd, yyyy");

            NewsTitle.Text = HeadLine;
            NewsTitle.NavigateUrl = commonfunctions.getQuickLink(newsId); ;

        }
    }
Example #27
0
 public void PrependWithAttrWithAnotherOwnerDocumentThrows()
 {
     XmlDocument doc = CreateDocumentWithElement();
     XmlAttribute anotherDocumentAttr = new XmlDocument().CreateAttribute("attr");
     XmlAttributeCollection target = doc.DocumentElement.Attributes;
     Assert.Throws<ArgumentException>(() => target.Prepend(anotherDocumentAttr));
 }
Example #28
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     XmlDocument document = new XmlDocument();
     string serverPath = Public.GetServerPath();
     document.Load(serverPath + @"\\bin\\DataMessage.xml");
     foreach (XmlNode node in document.SelectNodes("/DataMessage/DataTableItem"))
     {
         XmlElement element = (XmlElement)node;
         if (element.GetAttribute("TableName") == this.txtTableNameVal.Value.Trim())
         {
             element.SetAttribute("TableName", this.txtTableName.Text.Trim());
             element.SetAttribute("Text", this.txtTableChina.Text.Trim());
             foreach (XmlNode node2 in element.ChildNodes)
             {
                 XmlElement element2 = (XmlElement)node2;
                 if (element2.GetAttribute("ColumnName") == this.txtColNameVal.Value.Trim())
                 {
                     element2.InnerText = this.txtColChina.Text.Trim();
                     element2.SetAttribute("ColumnName", this.txtColName.Text.Trim());
                     element2.SetAttribute("ColumnType", this.ddlDataType.SelectedValue);
                     break;
                 }
             }
             break;
         }
     }
     document.Save(serverPath + @"\\bin\\DataMessage.xml");
     Public.Show("修改成功!");
     this.ClearForm();
     this.BindTableMess();
     this.ddlTableName_SelectedIndexChanged(sender, e);
 }
Example #29
0
    void Start()
    {
        strength = 1;
        agility = 3;
        endurance = 3;

        carryWeight = 3 + (2 * strength);
        hitPoint = strength * 20;
        meleeDamage = strength; //В процентах

        precision = agility; //В процентах
        armorClass = agility / 2;
        sequence = agility;

        dodge = endurance * 3;
        resistance = endurance / 2;
        recovery = endurance * 10;

        Debug.Log(hitPoint);
        XmlDocument xDoc = new XmlDocument();
        xDoc.Load("./Assets/Scripts/Data/enemiesAttributes.xml");
        XmlElement xRoot = xDoc.DocumentElement;
        foreach (XmlNode xnode in xRoot) {
            if (xnode.Attributes.Count > 0)
            {
                XmlNode attr = xnode.Attributes.GetNamedItem("name");
                if (attr != null)
                    Debug.Log(attr.Value);
            }
        }
    }
Example #30
0
        public static void GetAttributesOnCommentNode()
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml("<a><!-- comment --></a>");

            Assert.Null(xmlDocument.DocumentElement.FirstChild.Attributes);
        }