public IDictionary<String, String> getWeatherData(String lat, String lon) { XmlDataDocument doc = new XmlDataDocument(); IDictionary<String, String> data = new Dictionary<String, String>(); String url ="http://api.openweathermap.org/data/2.5/forecast/daily?lat=" + lat + "&lon=" + lon + "&cnt=5&mode=xml"; doc.Load(url); XmlNodeList locationList = doc.GetElementsByTagName("location"); XmlNodeList foreCastList = doc.GetElementsByTagName("time"); data["City"] = locationList[0].SelectSingleNode("name").InnerText; data["Country"] = locationList[0].SelectSingleNode("country").InnerText; String temperature,wind,clouds; for (int i = 0; i < 5; i++) { temperature = "Temperature : Morn = " + foreCastList[i].SelectSingleNode("temperature").Attributes["morn"].Value + ",Evening = " + foreCastList[i].SelectSingleNode("temperature").Attributes["eve"].Value + ",Night = " + foreCastList[i].SelectSingleNode("temperature").Attributes["night"].Value; wind = "Wind : " + foreCastList[i].SelectSingleNode("windSpeed").Attributes["name"].Value; clouds = "Clouds : " + foreCastList[i].SelectSingleNode("clouds").Attributes["value"].Value; data[foreCastList[i].Attributes["day"].Value] = temperature + " | " + wind + " | " + clouds; } return data; }
public IDictionary<String, String> getLatLong(String zipCode) { XmlDataDocument doc = new XmlDataDocument(); List<String> data = new List<String>(); String url = "http://maps.googleapis.com/maps/api/geocode/xml?address=" + zipCode; doc.Load(url); XmlNodeList status = doc.GetElementsByTagName("status"); String res_status = status[0].InnerText; if (!res_status.Equals("OK")) { data.Add("No Result"); } XmlNodeList result = doc.GetElementsByTagName("result"); XmlNodeList list = null,location = null; String latitude = null, longitude = null; for (int i = 0; i < result.Count; i++) { list = doc.GetElementsByTagName("geometry"); } for (int i = 0; i < list.Count; i++) { location = doc.GetElementsByTagName("location"); } latitude = location[0].SelectSingleNode("lat").InnerText; longitude = location[0].SelectSingleNode("lng").InnerText; return getWeatherData(latitude,longitude); }
protected void Page_Load(object sender, EventArgs e) { //try //{ if (this.RssUrl.Length == 0) throw new ApplicationException("Не указана ссылка на RSS-ленту."); XmlDataDocument feed = new XmlDataDocument(); feed.Load(GetFullUrl(this.RssUrl)); XmlNodeList posts = feed.GetElementsByTagName("item"); DataTable table = new DataTable("Feed"); table.Columns.Add("Title", typeof(string)); table.Columns.Add("Description", typeof(string)); table.Columns.Add("Link", typeof(string)); table.Columns.Add("PubDate", typeof(DateTime)); foreach (XmlNode post in posts) { DataRow row = table.NewRow(); row["Title"] = post["title"].InnerText; row["Description"] = post["description"].InnerText.Trim(); row["Link"] = post["link"].InnerText; row["PubDate"] = DateTime.Parse(post["pubDate"].InnerText); table.Rows.Add(row); } dlArticles.DataSource = table; dlArticles.DataBind(); //} /*catch (Exception) { this.Visible = false; }*/ }
private void createCsvFile() { XmlDataDocument xmldoc = new XmlDataDocument(); string name = null; string year = null; string corp = null; string line = null; string code = null; XmlNodeList childs = null; StreamWriter file = new StreamWriter(mamePath + "roms.csv", false); FileStream fs = new FileStream(mamePath + "mame.xml", FileMode.Open, FileAccess.Read); xmldoc.Load(fs); XmlNodeList machineNodes = xmldoc.GetElementsByTagName("machine"); for (int i = 0; i < machineNodes.Count; i++) { code = machineNodes[i].Attributes.GetNamedItem("name").InnerText.Trim(); childs = machineNodes[i].ChildNodes; name = childs.Count > 0 ? childs.Item(0).InnerText.Trim() : ""; year = childs.Count > 1 ? childs.Item(1).InnerText.Trim() : ""; corp = childs.Count > 2 ? childs.Item(2).InnerText.Trim() : ""; line = segment(code) + ", " + segment(name) + ", " + segment(year) + ", " + segment(corp); file.WriteLine(line); //if (i > 10) { // break; //} } file.Close(); fs.Close(); }
private void button1_Click(object sender, System.EventArgs e) { XmlDataDocument doc = new XmlDataDocument (); doc.Load ( "locdata.xml" ); XmlNodeList nodes = doc.GetElementsByTagName("city"); foreach ( XmlNode n in nodes ) { listBox1.Items.Add ( n.InnerText ); } label1.Text = string.Format("Total {0} Item(s).", listBox1.Items.Count); // StreamReader reader = new StreamReader ( "loctest2.csv" ); // string contents = reader.ReadToEnd (); // reader.Close (); // foreach ( string s in contents.Split ( "\n\r".ToCharArray() ) ) // { // if ( s.Trim() == string.Empty ) continue; // foreach ( string p in s.Split ( ",".ToCharArray() ) ) // { // string temp = p.Replace ( "\"", "" ); // listBox1.Items.Add ( temp.Trim() ); // } // // // } }
public void readChannelFeed() { XmlDataDocument xmldoc = new XmlDataDocument(); XmlNodeList xmlnode; int i = 0; //string str = null; xmldoc.Load(formHTTPrequest()); xmlnode = xmldoc.GetElementsByTagName("feed"); feedCount = xmlnode.Count; dates = new string[xmlnode.Count]; ids = new string[xmlnode.Count]; temp = new string[xmlnode.Count]; air = new string[xmlnode.Count]; soil = new string[xmlnode.Count]; light = new string[xmlnode.Count]; co2_1 = new string[xmlnode.Count]; co2_2 = new string[xmlnode.Count]; out_temp = new string[xmlnode.Count]; for (i = 0; i <= xmlnode.Count - 1; i++) { dates[i] = xmlnode[i].ChildNodes.Item(0).InnerText.Trim(); ids[i] = xmlnode[i].ChildNodes.Item(1).InnerText.Trim(); temp[i] = xmlnode[i].ChildNodes.Item(2).InnerText.Trim(); air[i] = xmlnode[i].ChildNodes.Item(3).InnerText.Trim(); soil[i] = xmlnode[i].ChildNodes.Item(4).InnerText.Trim(); light[i] = xmlnode[i].ChildNodes.Item(5).InnerText.Trim(); co2_1[i] = xmlnode[i].ChildNodes.Item(6).InnerText.Trim(); co2_2[i] = xmlnode[i].ChildNodes.Item(7).InnerText.Trim(); out_temp[i] = xmlnode[i].ChildNodes.Item(8).InnerText.Trim(); } }
static void Main(string[] args) { ArrayList plcInterfaceList = new ArrayList(); ArrayList simInterfaceList = new ArrayList(); string filename = "config.xml"; var currentDirectory = Directory.GetCurrentDirectory(); var configFilepath = Path.Combine(currentDirectory, filename); System.Xml.XmlDataDocument xmldoc = new System.Xml.XmlDataDocument(); XmlNodeList xmlAddresses; string str = null; FileStream fs = new FileStream(configFilepath, FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlAddresses = xmldoc.GetElementsByTagName("Address"); var numOfPlcs = xmlAddresses.Count; for (int i = 0; i < numOfPlcs; i++) { string amsAddress = xmlAddresses[i].ChildNodes.Item(0).InnerText.Trim(); Console.WriteLine("AmsNetId: {0}", amsAddress); PlcInterface plcInterface = new PlcInterface(amsAddress); plcInterfaceList.Add(plcInterface); plcInterface.Fetch(); SimInterface simInterface = new SimInterface(plcInterface); simInterfaceList.Add(simInterface); simInterface.Init(); } Console.WriteLine("Press enter to end the program."); Console.WriteLine(); while (true) { if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(true); if (key.Key == ConsoleKey.Enter) { break; } } } Console.WriteLine("Cleaning up and exiting."); foreach (SimInterface simInterface in simInterfaceList) { simInterface.Dispose(); } foreach (PlcInterface plcInterface in plcInterfaceList) { plcInterface.Dispose(); } }
private void LoadNpcConfig(string path, out List <string> npcNames, out List <string> controlMechanisms, out List <Microsoft.DirectX.Vector3> positions, out List <string> characterNames, out List <string> actions) { controlMechanisms = new List <string>(); npcNames = new List <string>(); positions = new List <Microsoft.DirectX.Vector3>(); characterNames = new List <string>(); actions = new List <string>(); System.Xml.XmlDataDocument doc = new System.Xml.XmlDataDocument(); doc.Load(path); XmlNode rootNode = doc.GetElementsByTagName("List")[0]; foreach (XmlNode npcNode in rootNode.ChildNodes) { foreach (XmlNode node in npcNode.ChildNodes) { switch (node.Name) { case "Name": npcNames.Add(node.InnerText); break; case "Script": controlMechanisms.Add(node.InnerText); break; case "FSM": controlMechanisms.Add(node.InnerText); break; case "Position": Microsoft.DirectX.Vector3 position = new Microsoft.DirectX.Vector3(); int x = Convert.ToInt32(node.ChildNodes[0].InnerText); int z = Convert.ToInt32(node.ChildNodes[1].InnerText); position = terrain.Get3Dposition(new System.Drawing.Point(x, z)); positions.Add(position); break; case "Character": characterNames.Add(node.InnerText); break; case "Actions": actions.Add(node.InnerText); break; } } } }
/// <summary> /// Find the discount percentage applicable to the user /// </summary> /// <returns>Discount percentage</returns> public int FindDiscount() { int discountPercentage = 0; try { XmlDataDocument xmldoc = new XmlDataDocument(); XmlNodeList xmlnode; if (user is Employee) { FileStream fs = new FileStream(Directory.GetCurrentDirectory() + "\\ApplicableDiscounts\\EmployeeDiscount.xml", FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlnode = xmldoc.GetElementsByTagName("Discount"); String discount = xmlnode[0].FirstChild.Value; discountPercentage = Int32.Parse(discount); } if (user is Affiliate) { FileStream fs = new FileStream(Directory.GetCurrentDirectory() + "\\ApplicableDiscounts\\AffiliateDiscount.xml", FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlnode = xmldoc.GetElementsByTagName("Discount"); String discount = xmlnode[0].FirstChild.Value; discountPercentage = Int32.Parse(discount); } if (user is Customer && (user as Customer).AssociatedSinceYears >= 2) { FileStream fs = new FileStream(Directory.GetCurrentDirectory() + "\\ApplicableDiscounts\\CustomerDiscount.xml", FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlnode = xmldoc.GetElementsByTagName("Discount"); String discount = xmlnode[0].FirstChild.Value; discountPercentage = Int32.Parse(discount); } } catch(Exception ex) { Console.WriteLine("Exception while loading xml data for discount specific to to the type of user"); } return discountPercentage; }
protected override BankTransfer GetTransferEntry(string entry) { SieradzBankTransfer mBankTransfer = new SieradzBankTransfer(); #pragma warning disable 618 XmlDocument xmlNode = new XmlDataDocument(); #pragma warning restore 618 string datePattern = "d.m.yyyy"; DateTime currentDate = DateTime.Now; var bankDictionary = SieradzBankTransfersUtils.Instance; xmlNode.LoadXml(entry); //TODO it's possible to reduce that sphagetti? // IT FCKIN IS! @UCTT mBankTransfer.TransferInfo.Amount = xmlNode.GetElementsByTagName("Amount").Item(0).InnerText; mBankTransfer.TransferInfo.DestinationAccountNumber = xmlNode.GetElementsByTagName("DestinationAccountNumber").Item(0).InnerText; mBankTransfer.TransferInfo.DestinationPersonName = xmlNode.GetElementsByTagName("DestinationPersonName").Item(0).InnerText; mBankTransfer.TransferInfo.SourceAccountNumber = xmlNode.GetElementsByTagName("SourceAccountNumber").Item(0).InnerText; mBankTransfer.TransferInfo.TransferDate = currentDate.ToString(datePattern); mBankTransfer.TransferInfo.TransferTitle = xmlNode.GetElementsByTagName("TransferTitle").Item(0).InnerText; mBankTransfer.SourceBank = bankDictionary.GetBankName(mBankTransfer.TransferInfo.SourceAccountNumber.Substring(2, 4)); mBankTransfer.DestinationBank = bankDictionary.GetBankName(mBankTransfer.TransferInfo.DestinationAccountNumber.Substring(2, 4)); return mBankTransfer; }
public override List<BankTransfer> GetBankTransfers() { BankFileOperation = new SieradzFileOperation(); #pragma warning disable 618 XmlDocument xmlFile= new XmlDataDocument(); #pragma warning restore 618 List<BankTransfer> mBankTransferList = new List<BankTransfer>(); xmlFile.LoadXml(BankFileOperation.GetFileContent(SieradzBankFilesPathHolder.TransferFilesPath + @"mBankTransfers.xml")); foreach (var childNode in xmlFile.DocumentElement.ChildNodes) { mBankTransferList.Add(GetTransferEntry(xmlFile.GetElementsByTagName((string) childNode.GetType().GetProperty("Name").GetValue(childNode)).Item(0).OuterXml)); } return mBankTransferList; }
/// <summary> /// How to open and read an XML file in C# /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { XmlDataDocument xmldoc = new XmlDataDocument(); XmlNodeList xmlnode; int i = 0; string str = null; FileStream fs = new FileStream("product.xml", FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlnode = xmldoc.GetElementsByTagName("Product"); for (i = 0; i <= xmlnode.Count - 1; i++) { //xmlnode[i].ChildNodes.Item(0).InnerText.Trim(); str = xmlnode[i].ChildNodes.Item(0).InnerText.Trim() + " | " + xmlnode[i].ChildNodes.Item(1).InnerText.Trim() + " | " + xmlnode[i].ChildNodes.Item(2).InnerText.Trim(); MessageBox.Show(str); } }
public rainfallImportXML(String StationsFile, String ReadingsFile, ref Dictionary<string, List<StationReading>> precip) { Stations = new XmlDataDocument(); Readings = new XmlDataDocument(); dStations = new Dictionary<string, Station>(); dReadings = new List<Reading>(); dStationReadings = new Dictionary<string, StationReading>(); StreamReader sr = new StreamReader(StationsFile); String xmlStr = sr.ReadToEnd(); Stations.LoadXml(xmlStr); sr = new StreamReader(ReadingsFile); xmlStr = sr.ReadToEnd(); Readings.LoadXml(xmlStr); XmlNodeList root = Stations.GetElementsByTagName("site"); foreach (XmlNode n in root) { dStations.Add(n.ChildNodes[1].InnerXml, new Station(n.ChildNodes[1].InnerXml, Double.Parse(n.ChildNodes[3].InnerXml), Double.Parse(n.ChildNodes[4].InnerXml), n.ChildNodes[2].InnerXml)); } root = Readings.GetElementsByTagName("element"); foreach (XmlNode n in root) { dReadings.Add(new Reading(n.Attributes.GetNamedItem("station_id").Value, n.Attributes.GetNamedItem("date").Value, n.Attributes.GetNamedItem("precip_interval").Value, Double.Parse(n.Attributes.GetNamedItem("value").Value))); } Station curStation; foreach (Reading r in dReadings) { if (precip.ContainsKey(r.DataTime)) { curStation = dStations[r.StationID]; precip[r.DataTime].Add(new StationReading(curStation.Lat, curStation.Lon, r.Date, r.DataTime, r.Value)); } else { List<StationReading> lsr = new List<StationReading>(); curStation = dStations[r.StationID]; lsr.Add(new StationReading(curStation.Lat, curStation.Lon, r.Date, r.DataTime, r.Value)); precip.Add(r.DataTime, lsr); } } }
/* public string GetData(int value) { return string.Format("You entered: {0}", value); } public CompositeType GetDataUsingDataContract(CompositeType composite) { if (composite == null) { throw new ArgumentNullException("composite"); } if (composite.BoolValue) { composite.StringValue += "Suffix"; } return composite; }*/ public IDictionary<string, string> getCrimeData(String zipCode) { XmlDataDocument doc = new XmlDataDocument(); IDictionary<String, String> data = new Dictionary<String, String>(); String url = "https://azure.geodataservice.net/GeoDataService.svc/GetUSDemographics?includecrimedata=true&zipcode=" + zipCode ; doc.Load(url); XmlNodeList elementList = doc.GetElementsByTagName("element"); XmlNode root = elementList[0]; //Display the contents of the child nodes. if (root.HasChildNodes) { for (int i = 0; i < root.ChildNodes.Count; i++) { data.Add(root.ChildNodes[i].Name,root.ChildNodes[i].InnerText); } } return data; }
private void btnChoose_Click(object sender, RoutedEventArgs e) { flyPackages.IsOpen = true; lstPackages.Items.Clear(); WebResponse response = WebRequest.Create(@"https://realmofthemadgod.appspot.com/package/getPackages").GetResponse(); XmlDataDocument xmlDataDocument = new XmlDataDocument(); xmlDataDocument.Load(response.GetResponseStream()); XmlNodeList elementsByTagName = xmlDataDocument.GetElementsByTagName("Package"); for (int index = 0; index < elementsByTagName.Count; ++index) { string _name = elementsByTagName[index].ChildNodes.Item(0).InnerText.Trim(); string _id = elementsByTagName[index].Attributes["id"].Value; string _price = elementsByTagName[index].ChildNodes.Item(1).InnerText.Trim(); string _url = elementsByTagName[index].ChildNodes.Item(5).InnerText.Trim(); string _end = elementsByTagName[index].ChildNodes.Item(6).InnerText.Trim(); lstPackages.Items.Add("[" + _id + "] " + _name + " - " + _price + "gold"); } }
public List<ProcessMonitor> ReadingXml() { XmlDataDocument xmldoc = new XmlDataDocument(); XmlNodeList xmlnode; int i = 0; List<ProcessMonitor> processes = new List<ProcessMonitor>(); string path = Path.GetDirectoryName(Application.ExecutablePath)+"\\Process.xml"; FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlnode = xmldoc.GetElementsByTagName("ProcessMonitor"); for (i = 0; i <= xmlnode.Count - 1; i++) { ProcessMonitor process = new ProcessMonitor(); process.ProcessName = xmlnode[i].ChildNodes.Item(0).InnerText.Trim(); process.NotificationList = xmlnode[i].ChildNodes.Item(1).InnerText.Trim(); process.TimeInterval = xmlnode[i].ChildNodes.Item(2).InnerText.Trim(); process.NotificationSubject = xmlnode[i].ChildNodes.Item(3).InnerText.Trim(); process.NotificationMail = xmlnode[i].ChildNodes.Item(4).InnerText.Trim(); processes.Add(process); } return processes; }
private void button3_Click(object sender, EventArgs e) { XmlDocument doc = new XmlDocument(); //create a dataset DataSet ds = new DataSet("XMLProducts"); //connect to the northwind database and //select all of the rows from products table SqlConnection conn = new SqlConnection(_connectString); SqlDataAdapter da = new SqlDataAdapter("SELECT Title,userid,content FROM task", conn); //fill the dataset da.Fill(ds, "Products"); ds.WriteXml("sample.xml", XmlWriteMode.WriteSchema); //load data into grid dataGridView1.DataSource = ds.Tables[0]; //XmlDataDocument专门为DataSet而设计 doc = new XmlDataDocument(ds); //get all of the products elements XmlNodeList nodeLst = doc.GetElementsByTagName("Products"); textBox1.Text = ""; foreach (XmlNode node in nodeLst) { textBox1.Text += node.InnerXml + "\r\n"; } }
static void Main(string[] args) { string city = string.Empty; string country = string.Empty; string latitude = string.Empty; string longitude = string.Empty; string la_dir = string.Empty; string lo_dir = string.Empty; string green = string.Empty; SortedDictionary<string, XmlNode> dic = new SortedDictionary<string, XmlNode>(); XmlDataDocument doc = new XmlDataDocument(); doc.Load("locdata.xml"); XmlNodeList nodes = doc.GetElementsByTagName("loctest"); foreach (XmlNode nd in nodes) { dic.Add(nd.ChildNodes[0].InnerText, nd); } XmlNodeList mainnodes = doc.GetElementsByTagName("DataSet1"); mainnodes[0].RemoveAll(); foreach (string s in dic.Keys) { mainnodes[0].AppendChild(dic[s]); } doc.Save("locdata2.xml"); bool readloc = false; StreamWriter writer = new StreamWriter("pagal.txt"); XmlTextReader reader = new XmlTextReader("locdata2.xml"); while (reader.Read()) { if ((reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.EndElement)) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "loctest") { readloc = true; } if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "loctest") { readloc = false; } if (readloc == false && reader.Name == "loctest") { writer.WriteLine(city + " - " + country + " - " + latitude + " - " + longitude + " - " + green); continue; } switch (reader.Name) { case "city": city = reader.ReadInnerXml(); break; case "country": country = reader.ReadInnerXml(); break; case "green": green = reader.ReadInnerXml(); break; case "latitude": latitude = reader.ReadInnerXml(); break; case "longitude": longitude = reader.ReadInnerXml(); break; case "la_dir": la_dir = reader.ReadInnerXml(); break; case "lo_dir": lo_dir = reader.ReadInnerXml(); break; } } } reader.Close(); writer.Close(); }
public static string[] retVetor(string src, bool ehSEL) { FileStream fs = new FileStream(src, FileMode.Open, FileAccess.Read); string[] vetor = { "." }; XmlDataDocument xmldoc = new XmlDataDocument(); XmlNodeList xmlnode; int i = 0; int j = 0; string CHK, SEL, VALUE; //Carrega XML... xmldoc.Load(fs); xmlnode = xmldoc.GetElementsByTagName("item"); for (i = 0; i <= xmlnode.Count - 1; i++) { xmlnode[i].ChildNodes.Item(0).InnerText.Trim(); // CHK = xmlnode[i].ChildNodes.Item(0).InnerText.Trim(); SEL = xmlnode[i].ChildNodes.Item(1).InnerText.Trim(); VALUE = xmlnode[i].ChildNodes.Item(2).InnerText.Trim(); // if (CHK == "1") { if (ehSEL) { vetor[j] = SEL; } else { vetor[j] = VALUE; } // j++; Array.Resize(ref vetor, j + 1); } } if (vetor != null) { Array.Resize(ref vetor, j); return vetor; } else { return null; } }
public static void BuildEntryDatabase() { XmlDataDocument AccessoryTable = new XmlDataDocument(); AccessoryTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\accessorytable.xml"); XmlNodeList NodeList = AccessoryTable.GetElementsByTagName("DefineAssetString"); AccessoryFilter = new Filter<ulong>(NodeList.Count, 0.01f, delegate(ulong Input) { return 0; }); foreach (XmlNode Node in NodeList) { ulong ID = Convert.ToUInt64(Node.Attributes["assetID"].Value, 16); AccessoryFilter.Add(ID); } XmlDataDocument AnimTable = new XmlDataDocument(); AnimTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\animtable.xml"); NodeList = AnimTable.GetElementsByTagName("DefineAssetString"); AnimFilter = new Filter<ulong>(NodeList.Count, 0.01f, delegate(ulong Input) { return 0; }); foreach (XmlNode Node in NodeList) { ulong ID = Convert.ToUInt64(Node.Attributes["assetID"].Value, 16); AnimFilter.Add(ID); } }
/// <summary> /// Find the general discount which is applicable irrespective of the user type /// </summary> /// <returns>Discount value</returns> public double FindGeneralDiscount() { double discountValue = 0; try { XmlDataDocument xmldoc = new XmlDataDocument(); XmlNodeList xmlnode; FileStream fs = new FileStream(Directory.GetCurrentDirectory() + "\\ApplicableDiscounts\\GeneralDiscount.xml", FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlnode = xmldoc.GetElementsByTagName("DiscountPerHundredDollar"); String discount = xmlnode[0].FirstChild.Value; discountValue = Double.Parse(discount); } catch(Exception ex) { Console.WriteLine("Exception while loading xml data for general discount"); } return discountValue; }
public void Test3() { XmlDataDocument DataDoc = new XmlDataDocument(); DataSet dataset = DataDoc.DataSet; dataset.ReadXmlSchema(new StringReader(RegionXsd)); DataDoc.Load(new StringReader(RegionXml)); DataDoc.GetElementsByTagName("Region")[0].RemoveAll(); TextWriter text = new StringWriter(); text.NewLine = "\n"; dataset.WriteXml(text); //DataDoc.Save (text); string TextString = text.ToString(); string substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf("<Root>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.Equal(" <Region />", substring); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.Equal(" <Region>", substring); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.Equal(" <RegionID>2</RegionID>", substring); substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' })); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); // Regardless of NewLine value, original xml contains CR // (but in the context of XML spec, it should be normalized) Assert.Equal(" <RegionDescription>Western", substring); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </RegionDescription>") != -1); substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' })); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.Equal(" </Region>", substring); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <RegionID>3</RegionID>") != -1); substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' })); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); // Regardless of NewLine value, original xml contains CR // (but in the context of XML spec, it should be normalized) Assert.Equal(" <RegionDescription>Northern", substring); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </RegionDescription>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <RegionID>4</RegionID>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <RegionDescription>Southern") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </RegionDescription>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </Region>") != -1); substring = TextString.Substring(0, TextString.Length); Assert.True(substring.IndexOf("</Root>") != -1); }
private void LoadLocationData( string filename ) { XmlDataDocument doc = new XmlDataDocument ( ); doc.Load ( filename ); XmlNodeList nodes = doc.GetElementsByTagName ( "loctest" ); foreach ( XmlNode node in nodes ) { string city = toProperCase(node.ChildNodes[0].InnerText); string country = toProperCase(node.ChildNodes[1].InnerText); string gmt = node.ChildNodes[3].InnerText; string la_dir = node.ChildNodes[4].InnerText; string la = node.ChildNodes[5].InnerText; string lo_dir = node.ChildNodes[6].InnerText; string lo = node.ChildNodes[7].InnerText; double latitude = double.Parse ( la ); double longitude = double.Parse ( lo ); bool sign = gmt[0] == '+' ? false : true; latitude = la_dir == "NORTH" ? latitude : -latitude; longitude = lo_dir == "EAST" ? longitude : -longitude; double GMTDiff = TimeSpan.Parse ( gmt.Remove (0,1) ).TotalHours; GMTDiff = sign ? -GMTDiff : GMTDiff; LocDataElement elt = new LocDataElement(); elt.City = city; elt.Country = country; elt.DaylightAdjustment = 0; elt.GMTDiff = GMTDiff; elt.Latitude = latitude; elt.Longitude = longitude; locdata.Add(elt); locdatalist.Add(elt); } }
protected void Application_AuthenticateRequest(Object sender, EventArgs e) { return; // 获取用户名 string cookieName = FormsAuthentication.FormsCookieName; HttpCookie authCookie = Context.Request.Cookies[cookieName]; if (null == authCookie) { Response.Redirect("http://Main.mes.clpec/clpec_main/LogonNew.aspx"); return; } FormsAuthenticationTicket authTicket = null; try { authTicket = FormsAuthentication.Decrypt(authCookie.Value); } catch (Exception ex) { Response.Redirect("http://Main.mes.clpec/clpec_main/LogonNew.aspx"); return; } if (null == authTicket) { Response.Redirect("http://Main.mes.clpec/clpec_main/LogonNew.aspx"); return; } if (authTicket.Expired) { Response.Redirect("http://Main.mes.clpec/clpec_main/LogonNew.aspx"); return; } string userId; userId = authTicket.UserData.ToString(); int index = userId.IndexOf("|"); userId = userId.Substring(0, index); if (Context.Request.HttpMethod.ToUpper() != "POST") { string strURL = Context.Request.Path.ToString(); string strPermission = ""; if (strURL.EndsWith("MainFrame.aspx") || strURL.EndsWith("Left1.aspx")) { return; } //获取权限集合 AuditService userAuth = new AuditService(); string strCategory = System.Configuration.ConfigurationSettings.AppSettings["PermissionCategory"]; DataSet dsPermission = new DataSet(); dsPermission = userAuth.ListUserPMSByCate(userId, strCategory) as DataSet; //读取配置文件 System.Xml.XmlDocument document = new System.Xml.XmlDataDocument(); document.Load(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Menu.xml"); XmlNodeList myList = document.GetElementsByTagName("MenuItem"); foreach (XmlNode myNode in myList) { string strHref = myNode.Attributes["href"].Value; if (strHref.EndsWith(strURL)) { strPermission = myNode.Attributes["permission"].Value; } } //check permission DataTable myTable; myTable = dsPermission.Tables[0]; // Presuming the DataTable has a column named Date. string strExpr; strExpr = "PMS_ID= " + "'" + strPermission + "'"; DataRow[] foundRows; // Use the Select method to find all rows matching the filter. foundRows = myTable.Select(strExpr); // Print column 0 of each returned row. if (foundRows.Length < 1) { Response.Redirect("http://main.mes.clpec/Clpec_Main/LogonNew.aspx"); return; } } string[] Roles = authTicket.UserData.Split('|'); FormsIdentity id = new FormsIdentity(authTicket); // This principal will flow throughout the request. GenericPrincipal principal = new GenericPrincipal(id, Roles); // Attach the new principal object to the current HttpContext object Context.User = principal; // // Extract the forms authentication cookie // string cookieName = FormsAuthentication.FormsCookieName; // HttpCookie authCookie = Context.Request.Cookies[cookieName]; // // if(null == authCookie) // { // // There is no authentication cookie. // return; // } // // FormsAuthenticationTicket authTicket = null; // try // { // authTicket = FormsAuthentication.Decrypt(authCookie.Value); // } // catch (Exception ex) // { // // Log exception details (omitted for simplicity) // return; // } // // if (null == authTicket) // { // // Cookie failed to decrypt. // return; // } // // if(authTicket.Expired) // { // return; // } // // // When the ticket was created, the UserData property was assigned a // // pipe delimited string of role names. // // // // // DataSet ds =new DataSet(); // // AuditService Audit= new AuditService(); // // string strCategory=System.Configuration.ConfigurationSettings.AppSettings["PMSCategory"]; // // ds=Audit.ListUserPMSByCate(authTicket.UserData.ToString(),strCategory); // // // StringCollection myCol = new StringCollection(); // // // // foreach(DataRow myRow in ds.Tables[0].Rows) // // { // // myCol.Add(myRow["PMS_ID"].ToString()); // // } // // String[] Roles = new String[myCol.Count]; // // myCol.CopyTo( Roles, 0 ); // // // string[] Roles = authTicket.UserData.Split('|'); // // // FormsIdentity id = new FormsIdentity( authTicket ); // // // This principal will flow throughout the request. // GenericPrincipal principal = new GenericPrincipal(id, Roles); // // Attach the new principal object to the current HttpContext object // Context.User = principal; }
public XmlDataDocument GetXML(bool useOuter) { try { logger.Debug("GetXML begin useOuter=" + useOuter.ToString()); if (this.m_DataSet != null) { // Use the XmlDataDocument to write your dataset instead of DataSet System.Xml.XmlDataDocument xmlDocument = new XmlDataDocument(); xmlDocument.LoadXml(this.m_DataSet.GetXml()); System.Xml.XmlDataDocument xmlDocument2 = new XmlDataDocument(); if (useOuter) { xmlDocument2.LoadXml(xmlDocument.InnerXml); if (xmlDocument2.DocumentElement.Name == "BOXES") { XmlNodeList boxList = xmlDocument2.GetElementsByTagName("BOX"); foreach (XmlNode boxNode in boxList) { for (int i = 0; i < 3; i++) { //XmlNode head = boxNode.SelectSingleNode("CONFIG_ID_NUMBER"); XmlNode head = boxNode.ChildNodes[77]; boxNode.RemoveChild(head); boxNode.InsertBefore(head, boxNode.SelectSingleNode("UDF_BOX")); } } } else if (xmlDocument2.DocumentElement.Name == "PALLETS") { XmlNodeList boxList = xmlDocument2.GetElementsByTagName("BOX"); if (boxList.Count>0) { foreach (XmlNode boxNode in boxList) { for (int i = 0; i < 3;i++) { //XmlNode head = boxNode.SelectSingleNode("CONFIG_ID_NUMBER"); Pallet B XmlNode head = boxNode.ChildNodes[2]; boxNode.RemoveChild(head); boxNode.InsertAfter(head, boxNode.LastChild); } } } } } else { //is packing list xmlDocument2.LoadXml(xmlDocument.ChildNodes[0].InnerXml); if (xmlDocument2.ChildNodes[0].Name == "PACK_ID") { XmlNodeList boxList = xmlDocument2.GetElementsByTagName("BOX"); foreach (XmlNode boxNode in boxList) { if (boxNode.ChildNodes.Count >= 6) { //if we have more than 5 child, more than 0 serial num //for (int i = 5; i < boxNode.ChildNodes.Count; i++) for (int i = 5; i < 6; i++) { //XmlNode head = boxNode.SelectSingleNode("UDF_BOX"); XmlNode serialNumNode = boxNode.ChildNodes[i]; boxNode.RemoveChild(serialNumNode); boxNode.InsertAfter(serialNumNode, boxNode.ChildNodes[0]); } //---------- for smart PC test 20100429------------------- /* for (int i = 1; i < 4; i++) { XmlNode serialNumNode = boxNode.ChildNodes[i]; boxNode.RemoveChild(serialNumNode); boxNode.InsertAfter(serialNumNode, boxNode.SelectSingleNode("SERIAL_NUM")); }*/ } } } else if (xmlDocument2.ChildNodes[0].Name == "TRUCK") { XmlNodeList boxList = xmlDocument2.GetElementsByTagName("BOXES"); if (boxList.Count > 0) { foreach (XmlNode boxNode in boxList) { for (int i = 0; i < 3; i++) { //XmlNode head = boxNode.SelectSingleNode("CONFIG_ID_NUMBER"); Pallet B XmlNode head = boxNode.ChildNodes[2]; boxNode.RemoveChild(head); boxNode.InsertAfter(head, boxNode.LastChild); } } } } } return xmlDocument2; } return null; } catch (Exception ex) { logger.Error("GetXML exception: " + ex.Message + Environment.NewLine + ex.StackTrace); #if DEBUG m_Nlogger.Info(string.Format("{0} \n\t {1}", "WriteXml", ex.Message)); #endif throw; } finally { logger.Debug("GetXML end useOuter=" + useOuter.ToString()); } return null; }
string ITnUtilitiesFile.ReadValueFromXmlFile(string tag_name, string file_name, string path) { string value = ""; try { XmlDataDocument xmldoc = new XmlDataDocument(); XmlNodeList xmlnode; string nameXml = ""; if (path != " ") { nameXml = path + file_name + ".tnx"; } else { nameXml = file_name + ".tnx"; } FileStream fs = new FileStream(nameXml, FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlnode = xmldoc.GetElementsByTagName(tag_name); value = xmlnode.Item(0).InnerText; } catch { } return value; }
string[,] ITnUtilitiesFile.ReadUserInfoFromXmlFile(string name, string path) { string[,] objWithVal = new string[,] { { "", "" } }; try { XmlDataDocument xmldoc = new XmlDataDocument(); XmlNodeList xmlnode; string nameXml = ""; if (path != " ") { nameXml = path + name + ".tnx"; } else { nameXml = name + ".tnx"; } IEncrypt encrypt = new TnEncrypt(); string _key = "tn"; FileStream fs = new FileStream(nameXml, FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlnode = xmldoc.GetElementsByTagName("server"); string server = xmlnode.Item(0).InnerText; xmlnode = xmldoc.GetElementsByTagName("database"); string database = xmlnode.Item(0).InnerText; xmlnode = xmldoc.GetElementsByTagName("uid"); string user = xmlnode.Item(0).InnerText; xmlnode = xmldoc.GetElementsByTagName("pwd"); string pass = encrypt.Decrypt(xmlnode.Item(0).InnerText, _key, true); xmlnode = xmldoc.GetElementsByTagName("instance"); string instance = xmlnode.Item(0).InnerText; xmlnode = xmldoc.GetElementsByTagName("version"); string version = xmlnode.Item(0).InnerText; objWithVal = new string[,] { { "server", server }, { "database", database }, { "uid", user }, { "pwd", pass }, { "instance", instance }, { "version", version } }; fs.Close(); } catch (Exception e) { MessageBox.Show(e.Message); } return objWithVal; }
string ITnUtilitiesFile.ReadSqlInfo(string file_name, string path) { string sqlInfo = ""; try { XmlDataDocument xmldoc = new XmlDataDocument(); XmlNodeList xmlnode; string nameXml = ""; if (path != " ") { nameXml = path + file_name + ".tnx"; } else { nameXml = file_name + ".tnx"; } FileStream fs = new FileStream(nameXml, FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlnode = xmldoc.GetElementsByTagName("version"); sqlInfo = xmlnode.Item(0).InnerText; } catch { } return sqlInfo; }
List<List<string>> ITnUtilitiesFile.ReadLayersFormXmlFile(String name, String path) { List<List<string>> objWithVal = new List<List<String>>(); List<String> lstThua = new List<string>(); List<String> lstDuong = new List<string>(); List<String> lstHem = new List<string>(); List<String> lstGiadat = new List<string>(); try { XmlDataDocument xmldoc = new XmlDataDocument(); XmlNodeList xmlnode; string nameXml = ""; if (path != " ") { nameXml = path + name + ".tnx"; } else { nameXml = name + ".tnx"; } FileStream fs = new FileStream(nameXml, FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlnode = xmldoc.GetElementsByTagName("thua"); foreach (XmlNode node in xmlnode) { lstThua.Add(node.InnerText); } xmlnode = xmldoc.GetElementsByTagName("duong"); foreach (XmlNode node in xmlnode) { lstDuong.Add(node.InnerText); } xmlnode = xmldoc.GetElementsByTagName("hem"); foreach (XmlNode node in xmlnode) { lstHem.Add(node.InnerText); } xmlnode = xmldoc.GetElementsByTagName("thua_giadat"); foreach (XmlNode node in xmlnode) { lstGiadat.Add(node.InnerText); } objWithVal.Add(lstThua); objWithVal.Add(lstDuong); objWithVal.Add(lstHem); objWithVal.Add(lstGiadat); fs.Close(); } catch { } return objWithVal; }
static ContentManager() { m_Resources = new Dictionary<ulong, string>(); m_LoadedResources = new Dictionary<ulong, ContentResource>(); XmlDataDocument AnimTable = new XmlDataDocument(); AnimTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\animtable.xml"); XmlNodeList NodeList = AnimTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { ulong FileID = Convert.ToUInt64(Node.Attributes["assetID"].Value, 16); //TODO: Figure out when to use avatardata2 and avatardata3... string FileName = GlobalSettings.Default.StartupPath + "avatardata\\animations\\animations.dat"; m_Resources.Add(FileID, FileName); } XmlDataDocument UIGraphicsTable = new XmlDataDocument(); UIGraphicsTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\uigraphics.xml"); NodeList = UIGraphicsTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { ulong FileID = Convert.ToUInt64(Node.Attributes["assetID"].Value, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } else FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; m_Resources.Add(FileID, FileName); } XmlDataDocument CollectionsTable = new XmlDataDocument(); CollectionsTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\collections.xml"); NodeList = CollectionsTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { ulong FileID = Convert.ToUInt64(Node.Attributes["assetID"].Value, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } m_Resources.Add(FileID, FileName); } XmlDataDocument PurchasablesTable = new XmlDataDocument(); PurchasablesTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\purchasables.xml"); NodeList = PurchasablesTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { ulong FileID = Convert.ToUInt64(Node.Attributes["assetID"].Value, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } m_Resources.Add(FileID, FileName); } XmlDataDocument OutfitsTable = new XmlDataDocument(); OutfitsTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\alloutfits.xml"); NodeList = OutfitsTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { ulong FileID = Convert.ToUInt64(Node.Attributes["assetID"].Value, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } m_Resources.Add(FileID, FileName); } XmlDataDocument AppearancesTable = new XmlDataDocument(); AppearancesTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\appearances.xml"); NodeList = AppearancesTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { ulong FileID = Convert.ToUInt64(Node.Attributes["assetID"].Value, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } if (!m_Resources.ContainsKey(FileID)) m_Resources.Add(FileID, FileName); } XmlDataDocument ThumbnailsTable = new XmlDataDocument(); ThumbnailsTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\thumbnails.xml"); NodeList = ThumbnailsTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { ulong FileID = Convert.ToUInt64(Node.Attributes["assetID"].Value, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } m_Resources.Add(FileID, FileName); } XmlDataDocument MeshTable = new XmlDataDocument(); MeshTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\meshes.xml"); NodeList = MeshTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { ulong FileID = Convert.ToUInt64(Node.Attributes["assetID"].Value, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } if (!m_Resources.ContainsKey(FileID)) m_Resources.Add(FileID, FileName); } XmlDataDocument TextureTable = new XmlDataDocument(); TextureTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\textures.xml"); NodeList = TextureTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { ulong FileID = Convert.ToUInt64(Node.Attributes["assetID"].Value, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } if (!m_Resources.ContainsKey(FileID)) m_Resources.Add(FileID, FileName); } XmlDataDocument BindingsTable = new XmlDataDocument(); BindingsTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\bindings.xml"); NodeList = BindingsTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { ulong FileID = Convert.ToUInt64(Node.Attributes["assetID"].Value, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } if (!m_Resources.ContainsKey(FileID)) m_Resources.Add(FileID, FileName); } //m_CachedResources var cacheFiles = Directory.GetFiles(GameFacade.CacheDirectory); foreach (var file in cacheFiles) { var fileName = Path.GetFileNameWithoutExtension(file); m_CachedResources.Add(ulong.Parse(fileName), file); } m_Resources.Add(0x100000005, GlobalSettings.Default.StartupPath + "avatardata\\skeletons\\skeletons.dat"); initComplete = true; GameFacade.TriggerContentLoaderReady(); }
public void Test3() { XmlDataDocument DataDoc = new XmlDataDocument (); DataSet dataset = DataDoc.DataSet; dataset.ReadXmlSchema ("Test/System.Xml/region.xsd"); DataDoc.Load("Test/System.Xml/region.xml" ); DataDoc.GetElementsByTagName ("Region") [0].RemoveAll (); TextWriter text = new StringWriter (); text.NewLine = "\n"; dataset.WriteXml (text); //DataDoc.Save (text); string TextString = text.ToString (); string substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf ("<Root>") != -1, "#C01"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.AreEqual (" <Region />", substring, "#C02"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.AreEqual (" <Region>", substring, "#C03"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.AreEqual (" <RegionID>2</RegionID>", substring, "#C04"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); // Regardless of NewLine value, original xml contains CR // (but in the context of XML spec, it should be normalized) Assert.AreEqual (" <RegionDescription>Western", substring, "#C05"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </RegionDescription>") != -1, "#C06"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.AreEqual (" </Region>", substring, "#C07"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Region>") != -1, "#C08"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <RegionID>3</RegionID>") != -1, "#C09"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); // Regardless of NewLine value, original xml contains CR // (but in the context of XML spec, it should be normalized) Assert.AreEqual (" <RegionDescription>Northern", substring, "#C10"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </RegionDescription>") != -1, "#C11"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </Region>") != -1, "#C12"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Region>") != -1, "#C13"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <RegionID>4</RegionID>") != -1, "#C14"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <RegionDescription>Southern") != -1, "#C15"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </RegionDescription>") != -1, "#C16"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </Region>") != -1, "#C17"); substring = TextString.Substring (0, TextString.Length); Assert.IsTrue (substring.IndexOf ("</Root>") != -1, "#C18"); }
static ContentManager() { m_Resources = new Dictionary<ulong, string>(); m_LoadedResources = new Dictionary<ulong, byte[]>(); XmlDataDocument AnimTable = new XmlDataDocument(); AnimTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\animtable.xml"); XmlNodeList NodeList = AnimTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { string HexID = RemovePadding(Node.Attributes["assetID"].Value); ulong FileID = Convert.ToUInt64(HexID, 16); //TODO: Figure out when to use avatardata2 and avatardata3... string FileName = GlobalSettings.Default.StartupPath + "avatardata\\animations\\animations.dat"; if (!m_Resources.ContainsKey(FileID)) m_Resources.Add(FileID, FileName); } XmlDataDocument UIGraphicsTable = new XmlDataDocument(); UIGraphicsTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\uigraphics.xml"); NodeList = UIGraphicsTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { string HexID = RemovePadding(Node.Attributes["assetID"].Value); ulong FileID = Convert.ToUInt64(HexID, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } else FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; if(!m_Resources.ContainsKey(FileID)) m_Resources.Add(FileID, FileName); } XmlDataDocument CollectionsTable = new XmlDataDocument(); CollectionsTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\collections.xml"); NodeList = CollectionsTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { string HexID = RemovePadding(Node.Attributes["assetID"].Value); ulong FileID = Convert.ToUInt64(HexID, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } if (!m_Resources.ContainsKey(FileID)) m_Resources.Add(FileID, FileName); } XmlDataDocument PurchasablesTable = new XmlDataDocument(); PurchasablesTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\purchasables.xml"); NodeList = PurchasablesTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { string HexID = RemovePadding(Node.Attributes["assetID"].Value); ulong FileID = Convert.ToUInt64(HexID, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } if (!m_Resources.ContainsKey(FileID)) m_Resources.Add(FileID, FileName); } XmlDataDocument OutfitsTable = new XmlDataDocument(); OutfitsTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\alloutfits.xml"); NodeList = OutfitsTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { string HexID = RemovePadding(Node.Attributes["assetID"].Value); ulong FileID = Convert.ToUInt64(HexID, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } if (!m_Resources.ContainsKey(FileID)) m_Resources.Add(FileID, FileName); } XmlDataDocument AppearancesTable = new XmlDataDocument(); AppearancesTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\appearances.xml"); NodeList = AppearancesTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { string HexID = RemovePadding(Node.Attributes["assetID"].Value); ulong FileID = Convert.ToUInt64(HexID, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } if (!m_Resources.ContainsKey(FileID)) m_Resources.Add(FileID, FileName); } XmlDataDocument ThumbnailsTable = new XmlDataDocument(); ThumbnailsTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\thumbnails.xml"); NodeList = ThumbnailsTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { ulong FileID = Convert.ToUInt64(Node.Attributes["assetID"].Value, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } if (!m_Resources.ContainsKey(FileID)) m_Resources.Add(FileID, FileName); } XmlDataDocument MeshTable = new XmlDataDocument(); MeshTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\meshes.xml"); NodeList = MeshTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { string HexID = RemovePadding(Node.Attributes["assetID"].Value); ulong FileID = Convert.ToUInt64(HexID, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } if (!m_Resources.ContainsKey(FileID)) m_Resources.Add(FileID, FileName); } XmlDataDocument TextureTable = new XmlDataDocument(); TextureTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\textures.xml"); NodeList = TextureTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { string HexID = RemovePadding(Node.Attributes["assetID"].Value); ulong FileID = Convert.ToUInt64(HexID, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } if (!m_Resources.ContainsKey(FileID)) m_Resources.Add(FileID, FileName); } XmlDataDocument BindingsTable = new XmlDataDocument(); BindingsTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\bindings.xml"); NodeList = BindingsTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { string HexID = RemovePadding(Node.Attributes["assetID"].Value); ulong FileID = Convert.ToUInt64(HexID, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } if (!m_Resources.ContainsKey(FileID)) m_Resources.Add(FileID, FileName); } XmlDataDocument HandgroupsTable = new XmlDataDocument(); HandgroupsTable.Load(GlobalSettings.Default.StartupPath + "packingslips\\handgroups.xml"); NodeList = HandgroupsTable.GetElementsByTagName("DefineAssetString"); foreach (XmlNode Node in NodeList) { string HexID = RemovePadding(Node.Attributes["assetID"].Value); ulong FileID = Convert.ToUInt64(HexID, 16); string FileName = ""; if (Node.Attributes["key"].Value.Contains(".dat")) { FileName = GlobalSettings.Default.StartupPath + Node.Attributes["key"].Value; } if (!m_Resources.ContainsKey(FileID)) m_Resources.Add(FileID, FileName); } m_Resources.Add(0x100000005, GlobalSettings.Default.StartupPath + "avatardata\\skeletons\\skeletons.dat"); initComplete = true; }
string[,] ITnUtilitiesFile.ReadLayers4CalcFromXmlFile(string name, string path) { string[,] objWithVal = new string[,] { { "", "" } }; try { XmlDataDocument xmldoc = new XmlDataDocument(); XmlNodeList xmlnode; string nameXml = ""; if (path != " ") { nameXml = path + name + ".tnx"; } else { nameXml = name + ".tnx"; } FileStream fs = new FileStream(nameXml, FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlnode = xmldoc.GetElementsByTagName("thua"); string thua = xmlnode.Item(0).InnerText; xmlnode = xmldoc.GetElementsByTagName("duong"); string duong = xmlnode.Item(0).InnerText; xmlnode = xmldoc.GetElementsByTagName("hem"); string hem = xmlnode.Item(0).InnerText; xmlnode = xmldoc.GetElementsByTagName("duong_buffer_1m"); string duong_buffer_1m = xmlnode.Item(0).InnerText; xmlnode = xmldoc.GetElementsByTagName("duong_buffer_50m"); string duong_buffer_50m = xmlnode.Item(0).InnerText; xmlnode = xmldoc.GetElementsByTagName("duong_buffer_100m"); string duong_buffer_100m = xmlnode.Item(0).InnerText; xmlnode = xmldoc.GetElementsByTagName("duong_buffer_200m"); string duong_buffer_200m = xmlnode.Item(0).InnerText; xmlnode = xmldoc.GetElementsByTagName("hem_buffer_1m"); string hem_buffer_1m = xmlnode.Item(0).InnerText; xmlnode = xmldoc.GetElementsByTagName("hem_layer_buffer_1m"); string hem_layer_buffer_1m = xmlnode.Item(0).InnerText; xmlnode = xmldoc.GetElementsByTagName("hem_buffer_1m_crt_frm_layer"); string hem_buffer_1m_crt_frm_layer = xmlnode.Item(0).InnerText; //objWithVal = new string[,] { { "thua", thua }, { "duong", duong }, { "hem", hem } }; objWithVal = new string[,] {{"thua",thua},{"duong",duong},{"hem",hem},{"duong_buffer_1m",duong_buffer_1m}, {"duong_buffer_50m",duong_buffer_50m},{"duong_buffer_100m",duong_buffer_100m},{"duong_buffer_200m",duong_buffer_200m}, {"hem_buffer_1m",hem_buffer_1m},{"hem_layer_buffer_1m",hem_layer_buffer_1m},{"hem_buffer_1m_crt_frm_layer",hem_buffer_1m_crt_frm_layer}}; fs.Close(); } catch (Exception e) { MessageBox.Show(e.Message); } return objWithVal; }