public void Test6() { DataSet RegionDS = new DataSet(); RegionDS.ReadXmlSchema("Test/System.Xml/region.xsd"); XmlDataDocument DataDoc = new XmlDataDocument(RegionDS); DataDoc.Load("Test/System.Xml/region.xml"); DataDoc.DataSet.EnforceConstraints = false; XmlElement newNode = DataDoc.CreateElement("Region"); XmlElement newChildNode = DataDoc.CreateElement("RegionID"); newChildNode.InnerText = "64"; XmlElement newChildNode2 = null; try { newChildNode2 = DataDoc.CreateElement("something else"); Assert.Fail("#H01"); } catch (XmlException) { } newChildNode2 = DataDoc.CreateElement("something_else"); newChildNode2.InnerText = "test node"; newNode.AppendChild(newChildNode); newNode.AppendChild(newChildNode2); DataDoc.DocumentElement.AppendChild(newNode); TextWriter text = new StringWriter(); //DataDoc.Save (text); DataDoc.DataSet.WriteXml(text); string TextString = text.ToString(); string substring = TextString.Substring(0, TextString.IndexOf("\n") - 1); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); for (int i = 0; i < 21; i++) { substring = TextString.Substring(0, TextString.IndexOf("\n")); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); } Assert.IsTrue(substring.IndexOf(" <Region>") != -1, "#H03"); substring = TextString.Substring(0, TextString.IndexOf("\n")); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); Assert.IsTrue(substring.IndexOf(" <RegionID>64</RegionID>") != -1, "#H04"); substring = TextString.Substring(0, TextString.IndexOf("\n")); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); Assert.IsTrue(substring.IndexOf(" </Region>") != -1, "#H05"); substring = TextString.Substring(0, TextString.Length); Assert.IsTrue(substring.IndexOf("</Root>") != -1, "#H06"); }
private static void AddDebugText(string message, string style) { XmlElement table = dbgDoc.CreateElement("table"); XmlElement tr = dbgDoc.CreateElement("tr"); XmlElement tdTime = dbgDoc.CreateElement("td"); XmlAttribute aTime = dbgDoc.CreateAttribute("class"); aTime.InnerText = "time"; tdTime.Attributes.Append(aTime); tdTime.InnerText = AppTime.ToString(); XmlElement tdText = dbgDoc.CreateElement("td"); XmlAttribute aclass = dbgDoc.CreateAttribute("class"); aclass.InnerText = style; tdText.Attributes.Append(aclass); string encodedMessage = System.Web.HttpUtility.HtmlEncode(message); try { tdText.InnerXml = encodedMessage; } catch (Exception ex) { tdText.InnerText = "!!! Chyba pri zaznamenavani debug zpravy!!!!"; AddError("Chyba pri vkladani zpravy do logu! delka=" + message.Length + " - " + ex.ToString()); } table.AppendChild(tr); tr.AppendChild(tdTime); tr.AppendChild(tdText); dbgBodyNode.AppendChild(table); }
public XmlDocument GenerateXML() { XmlDataDocument doc = new XmlDataDocument(); XmlElement BPEL = doc.CreateElement(Parsing.BPEL_NODE_NAME); doc.AppendChild(BPEL); XmlElement assertion = doc.CreateElement(Parsing.ASSERTION_NODE_NAME); assertion.InnerText = Assertion; BPEL.AppendChild(assertion); if (PathContentMap.Count > 0) { XmlElement files = doc.CreateElement(Parsing.FILES_NODE_NAME); foreach (KeyValuePair <string, string> pair in PathContentMap) { XmlElement file = doc.CreateElement(Parsing.FILE_NODE_NAME); file.SetAttribute(Parsing.PATH_ATTR_NODE_NAME, pair.Key); if (!string.IsNullOrEmpty(pair.Value.Trim())) { file.InnerText = pair.Value; } files.AppendChild(file); } BPEL.AppendChild(files); } return(doc); }
public XmlDocument GenerateXML() { XmlDataDocument doc = new XmlDataDocument(); XmlElement LTS = doc.CreateElement(Parsing.LTS_NODE_NAME); doc.AppendChild(LTS); XmlElement declar = doc.CreateElement(Parsing.DECLARATION_NODE_NAME); declar.InnerText = Declaration; LTS.AppendChild(declar); XmlElement process = doc.CreateElement(Parsing.PROCESSES_NODE_NAME); foreach (TACanvas canvas in Processes) { process.AppendChild(canvas.WriteToXml(doc)); } LTS.AppendChild(process); XmlElement properties = doc.CreateElement(Parsing.PROPERTIES_NODE_NAME.Replace(" ", "_")); foreach (TACanvas canvas in Properties) { properties.AppendChild(canvas.WriteToXml(doc)); } LTS.AppendChild(properties); return(doc); }
public static bool AddOnlineUser(string QQNumber, string IpEndPoint) { string XmlUrl = "onlineinf\\onLine.xml"; if (!File.Exists(XmlUrl)) { File.Create(XmlUrl).Close(); StringBuilder add = new StringBuilder(); StreamWriter str = new StreamWriter(XmlUrl); add.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); add.Append("<root></root>"); str.Write(add.ToString()); str.Close(); } XmlDataDocument XmlData = new XmlDataDocument(); XmlData.Load(XmlUrl); XmlNode root = XmlData.SelectSingleNode("root"); if (!IsThisUserOnline(XmlData, QQNumber, IpEndPoint)) { XmlElement online = XmlData.CreateElement("online"); XmlElement QQnumber = XmlData.CreateElement("QQnumber"); XmlElement Ipendpoint = XmlData.CreateElement("IpEndPoint"); QQnumber.InnerText = QQNumber; Ipendpoint.InnerText = IpEndPoint; online.AppendChild(QQnumber); online.AppendChild(Ipendpoint); root.AppendChild(online); } XmlData.Save(XmlUrl); return(true); }
private void addFriendsToXML(string path, string uid) { #region TUserBusiness userbusiness = new TUserBusiness(); DataSet friends = userbusiness.GetFriendsByGroup(uid); XmlDataDocument temp = new XmlDataDocument(); temp.Load(path); XmlNodeList AllGroup = temp.SelectSingleNode("root").ChildNodes; foreach (XmlNode node in AllGroup) { string filter = string.Format("{0}='{1}'", GroupData.groupName, node.Attributes["groupName"].Value); DataRow[] drarr = friends.Tables[0].Select(filter); foreach (DataRow dr in drarr) { XmlElement friend = temp.CreateElement("friend"); XmlElement FriendNumber = temp.CreateElement("FriendNumber"); XmlElement FriendName = temp.CreateElement("FriendName"); XmlElement friendid = temp.CreateElement("FriendId"); FriendName.InnerText = dr["friendFullname"].ToString().Trim(); FriendNumber.InnerText = dr["friendQQ"].ToString().Trim(); friendid.InnerText = dr["friendId"].ToString().Trim(); friend.AppendChild(FriendNumber); friend.AppendChild(FriendName); friend.AppendChild(friendid); node.AppendChild(friend); //break; } } temp.Save(path); #endregion }
public void AddLink(string title, string uri) { XmlDocument doc = new XmlDataDocument(); doc.Load("RssLinks.xml"); XmlNode rootNode = doc.SelectSingleNode("links"); XmlNode linkNode = doc.CreateElement("link"); XmlNode titleNode = doc.CreateElement("title"); XmlText titleText = doc.CreateTextNode(title); titleNode.AppendChild(titleText); XmlNode uriNode = doc.CreateElement("uri"); XmlText uriText = doc.CreateTextNode(uri); uriNode.AppendChild(uriText); XmlNode defaultshowNode = doc.CreateElement("defaultshow"); XmlText defaultshowText = doc.CreateTextNode("false"); defaultshowNode.AppendChild(defaultshowText); linkNode.AppendChild(titleNode); linkNode.AppendChild(uriNode); linkNode.AppendChild(defaultshowNode); rootNode.AppendChild(linkNode); doc.Save("RssLinks.xml"); }
public void Test5() { DataSet RegionDS = new DataSet(); RegionDS.ReadXmlSchema("Test/System.Xml/region.xsd"); XmlDataDocument DataDoc = new XmlDataDocument(RegionDS); DataDoc.Load("Test/System.Xml/region.xml"); try { DataDoc.DocumentElement.AppendChild(DataDoc.DocumentElement.FirstChild); Assert.Fail("#G01"); } catch (InvalidOperationException e) { Assert.AreEqual(typeof(InvalidOperationException), e.GetType(), "#G02"); Assert.AreEqual("Please set DataSet.EnforceConstraints == false before trying to edit " + "XmlDataDocument using XML operations.", e.Message, "#G03"); DataDoc.DataSet.EnforceConstraints = false; } XmlElement newNode = DataDoc.CreateElement("Region"); XmlElement newChildNode = DataDoc.CreateElement("RegionID"); newChildNode.InnerText = "64"; XmlElement newChildNode2 = DataDoc.CreateElement("RegionDescription"); newChildNode2.InnerText = "test node"; newNode.AppendChild(newChildNode); newNode.AppendChild(newChildNode2); DataDoc.DocumentElement.AppendChild(newNode); TextWriter text = new StringWriter(); //DataDoc.Save (text); DataDoc.DataSet.WriteXml(text); string TextString = text.ToString(); string substring = TextString.Substring(0, TextString.IndexOf("\n")); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); for (int i = 0; i < 21; i++) { substring = TextString.Substring(0, TextString.IndexOf("\n")); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); } Assert.IsTrue(substring.IndexOf(" <Region>") != -1, "#G04"); substring = TextString.Substring(0, TextString.IndexOf("\n")); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); Assert.IsTrue(substring.IndexOf(" <RegionID>64</RegionID>") != -1, "#G05"); substring = TextString.Substring(0, TextString.IndexOf("\n")); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); Assert.IsTrue(substring.IndexOf(" <RegionDescription>test node</RegionDescription>") != -1, "#G06"); substring = TextString.Substring(0, TextString.IndexOf("\n")); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); Assert.IsTrue(substring.IndexOf(" </Region>") != -1, "#G07"); substring = TextString.Substring(0, TextString.Length); Assert.IsTrue(substring.IndexOf("</Root>") != -1, "#G08"); }
public static void InitLogger() { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); startTime = DateTime.Now; times = new List <DateTime>(); fpss = new List <int>(1000); stopwatches = new List <Stopwatch>(); doc = new XmlDataDocument(); doc.CreateXmlDeclaration("1.0", "UTF-8", "yes"); dbgDoc = new XmlDataDocument(); dbgDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes"); XmlElement html = doc.CreateElement("html"); XmlElement head = doc.CreateElement("head"); XmlElement link = doc.CreateElement("link"); XmlAttribute type = doc.CreateAttribute("type"); type.InnerText = "text/css"; link.Attributes.Append(type); XmlAttribute rel = doc.CreateAttribute("rel"); rel.InnerText = "Stylesheet"; link.Attributes.Append(rel); XmlAttribute href = doc.CreateAttribute("href"); href.InnerText = "logging.css"; link.Attributes.Append(href); head.AppendChild(link); html.AppendChild(head); XmlElement body = doc.CreateElement("body"); XmlElement text = doc.CreateElement("div"); text.InnerXml = "Logger verze 0.3; cas zacatku: " + startTime.ToString(); body.AppendChild(text); html.AppendChild(body); doc.AppendChild(html); dbgDoc = (XmlDataDocument)doc.CloneNode(true); bodyNode = doc.GetElementsByTagName("body")[0]; dbgBodyNode = dbgDoc.GetElementsByTagName("body")[0]; //Save(); bInitialized = true; Console.WriteLine("Logger spusten"); AddError("test"); }
public XmlNode ToSpml() { XmlDataDocument doc = new XmlDataDocument(); XmlElement conn = doc.CreateElement("Connection"); XmlAttribute url = doc.CreateAttribute("Url"); url.Value = Url.ToString(); conn.Attributes.Append(url); if (CustomAuthentication) { XmlAttribute user = doc.CreateAttribute("User"); user.Value = User ?? ""; conn.Attributes.Append(user); XmlAttribute password = doc.CreateAttribute("Password"); password.Value = Password ?? ""; conn.Attributes.Append(password); if (Domain != null) { XmlAttribute domain = doc.CreateAttribute("Domain"); domain.Value = Domain; conn.Attributes.Append(domain); } } return(conn); }
/// <summary> /// 添加strNewVariableName进m_Xmldoc /// </summary> /// <param name="strNewVariableName"></param> protected void AddNewNode(string strNewVariableName) { XmlElement NewVariable = m_XmlDoc.CreateElement("variable"); XmlElement NewName = m_XmlDoc.CreateElement("name"); XmlElement NewTypeId = m_XmlDoc.CreateElement("typeid"); XmlText name = m_XmlDoc.CreateTextNode(strNewVariableName); XmlText typeid = m_XmlDoc.CreateTextNode(m_strTypeId); NewVariable.AppendChild(NewName); NewVariable.AppendChild(NewTypeId); NewName.AppendChild(name); NewTypeId.AppendChild(typeid); m_XmlDoc.DocumentElement.AppendChild(NewVariable); }
public string EncodeXml() { XmlDataDocument myXMLobj = new XmlDataDocument(); XmlElement myXML = myXMLobj.CreateElement("items"); EncodeNodes(Items, myXML, myXMLobj); return(myXML.OuterXml); }
/// <summary> /// 向m_XmlResult添加节点node1 /// </summary> /// <param name="node1"></param> protected void AddNode(XmlNode node1) { XmlElement root = m_XmlResult.DocumentElement; XmlElement newVariable = m_XmlResult.CreateElement("variable"); newVariable.InnerXml = node1.InnerXml; root.AppendChild(newVariable); }
private static void AddNode(string sUid, string sPwd, bool RememberMe) { bool isAdd = true; XmlDataDocument UserDate = new XmlDataDocument(); UserDate.Load(QQuser); XmlNode root = UserDate.SelectSingleNode("root"); for (int i = 0; i < root.ChildNodes.Count; i++) { if (root.ChildNodes[i].Attributes["user"].Value.Trim() == sUid) { //更新用户消息 if (RememberMe) { root.ChildNodes[i].ChildNodes[0].InnerText = sPwd; } else { root.ChildNodes[i].ChildNodes[0].InnerText = ""; } UserDate.Save(QQuser); isAdd = false; break; } } if (isAdd) { XmlNode NodeAtt = UserDate.CreateNode(XmlNodeType.Attribute, "user", null); XmlElement user = UserDate.CreateElement("user"); XmlElement pwd = UserDate.CreateElement("pwd"); user.Attributes.SetNamedItem(NodeAtt); user.Attributes["user"].Value = sUid; if (RememberMe) { pwd.InnerText = sPwd; } else { pwd.InnerText = ""; } user.AppendChild(pwd); root.AppendChild(user); UserDate.Save(QQuser); } }
public void CreateElement3() { XmlDataDocument doc = new XmlDataDocument(); doc.DataSet.ReadXmlSchema("Test/System.Xml/region.xsd"); doc.Load("Test/System.Xml/region.xml"); XmlElement Element = doc.CreateElement("ElementName", "namespace"); Assert.AreEqual(string.Empty, Element.Prefix, "test#01"); Assert.AreEqual("ElementName", Element.LocalName, "test#02"); Assert.AreEqual("namespace", Element.NamespaceURI, "test#03"); Element = doc.CreateElement("prefix:ElementName", "namespace"); Assert.AreEqual("prefix", Element.Prefix, "test#04"); Assert.AreEqual("ElementName", Element.LocalName, "test#05"); Assert.AreEqual("namespace", Element.NamespaceURI, "test#06"); }
private static void AddText(string message, string style, bool isProblem) { XmlElement table = doc.CreateElement("table"); XmlElement tr = doc.CreateElement("tr"); XmlElement tdTime = doc.CreateElement("td"); XmlAttribute aTime = doc.CreateAttribute("class"); aTime.InnerText = "time"; tdTime.Attributes.Append(aTime); tdTime.InnerText = AppTime.ToString(); XmlElement tdText = doc.CreateElement("td"); XmlAttribute aclass = doc.CreateAttribute("class"); aclass.InnerText = style; tdText.Attributes.Append(aclass); string encodedMessage = System.Web.HttpUtility.HtmlEncode(message); try { tdText.InnerXml = encodedMessage; } catch (Exception ex) { tdText.InnerText = "!!! Chyba pri zaznamenavani zpravy!!!!"; AddError("Chyba pri vkladani zpravy do logu! delka=" + message.Length + " - " + ex.ToString()); } table.AppendChild(tr); tr.AppendChild(tdTime); tr.AppendChild(tdText); bodyNode.AppendChild(table); if (bWriteToOutput) { System.Diagnostics.Debug.WriteLine(message); //System.Console.WriteLine(message); } if (isProblem) { AddDebugText(message, style); } }
public static void XmlDataDocument_CreateElement() { XmlDataDocument doc = new XmlDataDocument(); XmlElement element = doc.CreateElement("prefix", "localName", "namespaceURI"); Assert.NotNull(element); Assert.Equal("prefix", element.Prefix); Assert.Equal("prefix:localName", element.Name); Assert.Equal("namespaceURI", element.NamespaceURI); }
public void CreateXml(DataSet dataset_for_index_doc, DataSet dataset_for_folder, string indexing, string fullPath, string filename, SqlConnection connection, string folderID, string docID) { string temp_string = System.IO.Path.GetExtension(filename); string output_filename = filename.Replace(temp_string, ".xml"); string temp_fullpath = string.Format("{0}\\{1}", fullPath, output_filename); //String SQLCommand = " select * from obj where parent_id =" + indexing ; DataRow[] indexRow = dataset_for_index_doc.Tables[0].Select("DocID = " + docID); XmlDataDocument doc = new XmlDataDocument(); XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null); XmlElement root = doc.DocumentElement; doc.InsertBefore(xmlDeclaration, root); DataRow[] r = dataset_for_folder.Tables[0].Select("folderID = " + folderID); string temp_index_name = r[0].ItemArray[0].ToString().Replace(" ", ""); XmlElement element1 = doc.CreateElement(string.Empty, temp_index_name, string.Empty); doc.AppendChild(element1); //Create an element representing the first customer record. //foreach (DataRow row in ds.Tables[0].Rows) //{ // string temp_index_name1 = row.ItemArray[3].ToString().Replace(" ", ""); // XmlElement element2 = doc.CreateElement(string.Empty, temp_index_name1, string.Empty); // XmlText text1 = doc.CreateTextNode(row.ItemArray[3].ToString()); // element2.AppendChild(text1); // element1.AppendChild(element2); //} foreach (DataRow index in indexRow) { string temp_index_name1 = index.ItemArray[4].ToString().Replace(" ", ""); XmlElement element2 = doc.CreateElement(string.Empty, temp_index_name1, string.Empty); XmlText text1 = doc.CreateTextNode(index.ItemArray[3].ToString()); element2.AppendChild(text1); element1.AppendChild(element2); } doc.Save(temp_fullpath); }
public XmlDocument GenerateXML() { XmlDataDocument doc = new XmlDataDocument(); XmlElement UmlModel = doc.CreateElement(Parsing.UML_MODEL_NODE_NAME); doc.AppendChild(UmlModel); XmlElement assertion = doc.CreateElement(Parsing.ASSERTION_NODE_NAME); assertion.InnerText = this.Assertion; UmlModel.AppendChild(assertion); XmlElement diagrams = doc.CreateElement(Parsing.DIAGRAMS_NODE_NAME); foreach (var diagram in Diagrams) { XmlElement diagramTag = doc.CreateElement(Parsing.DIAGRAM_TAG); XmlElement diagramName = doc.CreateElement(Parsing.DIAGRAM_NAME); diagramName.InnerText = diagram.Key; diagramTag.AppendChild(diagramName); XmlElement xmiContent = doc.CreateElement(Parsing.DIAGRAM_XMI_CONTENT); xmiContent.InnerText = diagram.Value.XmiContent; diagramTag.AppendChild(xmiContent); diagrams.AppendChild(diagramTag); } UmlModel.AppendChild(diagrams); return(doc); }
private void save() { XmlDataDocument xml_doc = new XmlDataDocument(); XmlNode root = xml_doc.CreateElement("vocab"); foreach (LessonNode l in LessonStore) { XmlNode lesson = xml_doc.CreateElement("lesson"); XmlAttribute a_id = xml_doc.CreateAttribute("id"); XmlAttribute a_description = xml_doc.CreateAttribute("description"); a_id.Value = l.Id.ToString(); a_description.Value = l.Description; lesson.Attributes.Append(a_id); lesson.Attributes.Append(a_description); foreach (PairNode p in l.PairStore) { XmlNode pair = xml_doc.CreateElement("pair"); XmlNode en = xml_doc.CreateElement("en"); XmlNode de = xml_doc.CreateElement("de"); en.InnerText = p.En; de.InnerText = p.De; pair.AppendChild(en); pair.AppendChild(de); lesson.AppendChild(pair); } root.AppendChild(lesson); } xml_doc.AppendChild(root); xml_doc.Save(xml_path); }
/// <summary> /// 生成好友列表xml文件 /// </summary> /// <param name="UserNum">需要生成列表的用户名</param> /// <returns>返回生成的文件路径,"-1"意味着生成文件失败</returns> public string MakeFriendXml(string UserNum) { try { MakeRootFile(UserNum); FriendData = opDate.GetFriendLsit(UserNum); XmlNode AddHere = null; for (int i = 0; i < FriendData.Tables[0].Rows.Count; i++) { XmlDataDocument temp = new XmlDataDocument(); temp.Load("temp\\" + UserNum.Trim() + ".xml"); XmlElement friend = temp.CreateElement("friend"); XmlElement FriendNumber = temp.CreateElement("FriendNumber"); XmlElement FriendName = temp.CreateElement("FriendName"); string GroupName = FriendData.Tables[0].Rows[i]["cGroupName"].ToString().Trim(); XmlNodeList AllGroup = temp.SelectSingleNode("root").ChildNodes; foreach (XmlNode node in AllGroup) { if (node.Attributes["GroupName"].Value.Trim() == GroupName) { AddHere = node; FriendName.InnerText = FriendData.Tables[0].Rows[i]["cUserName"].ToString().Trim(); FriendNumber.InnerText = FriendData.Tables[0].Rows[i]["cFriendNum"].ToString().Trim(); friend.AppendChild(FriendNumber); friend.AppendChild(FriendName); AddHere.AppendChild(friend); break; } } temp.Save("temp\\" + UserNum.Trim() + ".xml"); } return("temp\\" + UserNum.Trim() + ".xml"); } catch { return("-1"); } }
public void CreateElement1() { XmlDataDocument doc = new XmlDataDocument(); doc.DataSet.ReadXmlSchema("Test/System.Xml/region.xsd"); doc.Load("Test/System.Xml/region.xml"); XmlElement Element = doc.CreateElement("prefix", "localname", "namespaceURI"); Assert.AreEqual("prefix", Element.Prefix, "test#01"); Assert.AreEqual("localname", Element.LocalName, "test#02"); Assert.AreEqual("namespaceURI", Element.NamespaceURI, "test#03"); doc.ImportNode(Element, false); TextWriter text = new StringWriter(); doc.Save(text); string substring = string.Empty; string TextString = text.ToString(); substring = TextString.Substring(0, TextString.IndexOf("\n")); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); substring = TextString.Substring(0, TextString.IndexOf("\n")); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); Assert.IsTrue(substring.IndexOf("<Root>") != -1, "test#05"); substring = TextString.Substring(0, TextString.IndexOf("\n")); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); Assert.IsTrue(substring.IndexOf(" <Region>") != -1, "test#06"); substring = TextString.Substring(0, TextString.IndexOf("\n")); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); Assert.IsTrue(substring.IndexOf(" <RegionID>1</RegionID>") != -1, "test#07"); for (int i = 0; i < 26; i++) { substring = TextString.Substring(0, TextString.IndexOf("\n")); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); } substring = TextString.Substring(0, TextString.Length); Assert.IsTrue(substring.IndexOf("</Root>") != -1, "test#08"); }
private static void ReplaceIdWithUid <T>(XmlDataDocument doc, ref bool isModified, string oldName, string newName, Dictionary <int, T> entitiesById) where T : EntityObject { XmlNode organization = doc.SelectSingleNode("/IncidentBoxDocument/Block/Param[@Name='" + oldName + "']"); if (organization != null) { string newValue = Guid.Empty.ToString("D"); XmlAttribute valueAttribute = organization.Attributes["Value"]; if (valueAttribute != null) { string oldValue = valueAttribute.Value; if (!string.IsNullOrEmpty(oldValue)) { XmlDocument docValue = new XmlDocument(); docValue.LoadXml(oldValue); XmlNode valueNode = docValue.SelectSingleNode("/int"); if (valueNode != null) { string valueString = valueNode.InnerText; if (!string.IsNullOrEmpty(valueString)) { int id; if (int.TryParse(valueString, out id)) { if (id > 0 && entitiesById.ContainsKey(id)) { newValue = entitiesById[id].PrimaryKeyId.Value.ToString(); } } } } } } XmlNode parentNode = organization.ParentNode; parentNode.RemoveChild(organization); XmlNode newParamNode = parentNode.AppendChild(doc.CreateElement("Param")); newParamNode.Attributes.Append(doc.CreateAttribute("Name")).Value = newName; newParamNode.Attributes.Append(doc.CreateAttribute("Value")).Value = newValue; isModified = true; } }
public void NewInstance() { XmlDataDocument doc = new XmlDataDocument(); AssertDataSet("#1", doc.DataSet, "NewDataSet", 0, 0); Assert.IsFalse(doc.DataSet.EnforceConstraints); XmlElement el = doc.CreateElement("TEST"); AssertDataSet("#2", doc.DataSet, "NewDataSet", 0, 0); Assert.IsNull(doc.GetRowFromElement(el)); doc.AppendChild(el); AssertDataSet("#3", doc.DataSet, "NewDataSet", 0, 0); DataSet ds = new DataSet(); doc = new XmlDataDocument(ds); Assert.IsTrue(doc.DataSet.EnforceConstraints); }
public XmlDocument GenerateXML() { XmlDataDocument doc = new XmlDataDocument(); XmlElement PddlModel = doc.CreateElement(Parsing.PDDL_MODEL_NODE_NAME); doc.AppendChild(PddlModel); XmlElement domain = doc.CreateElement(Parsing.DOMAIN_NODE_NAME); XmlElement dFileName = doc.CreateElement(Parsing.PDDL_FILE_NAME_TAG); dFileName.InnerText = Domain != null ? this.Domain.Name : " "; domain.AppendChild(dFileName); XmlElement dPath = doc.CreateElement(Parsing.PDDL_FILE_PATH_TAG); dPath.InnerText = Domain != null ? this.Domain.FilePath : " "; domain.AppendChild(dPath); PddlModel.AppendChild(domain); XmlElement diagrams = doc.CreateElement(Parsing.PROBLEMS_NODE_NAME); foreach (var problem in this.Problems) { XmlElement problemTag = doc.CreateElement(Parsing.PROBLEM_NAME); XmlElement problemName = doc.CreateElement(Parsing.PDDL_FILE_NAME_TAG); problemName.InnerText = problem.Key; problemTag.AppendChild(problemName); XmlElement problemPath = doc.CreateElement(Parsing.PDDL_FILE_PATH_TAG); problemPath.InnerText = problem.Value.FilePath; problemTag.AppendChild(problemPath); diagrams.AppendChild(problemTag); } PddlModel.AppendChild(diagrams); return(doc); }
private void EncodeNodes(TreeViewItemCollection NColl, XmlElement myXML, XmlDataDocument myXMLobj) { foreach (TreeViewItem Itm in NColl) { XmlElement nx = myXMLobj.CreateElement("item"); nx.SetAttribute("Text", Itm.Text); nx.SetAttribute("Image", Itm.Image); nx.SetAttribute("Link", Itm.Link); nx.SetAttribute("TargetFrame", Itm.TargetFrame); nx.SetAttribute("Open", Itm.Open.ToString()); nx.SetAttribute("value", Itm.Value); nx.SetAttribute("Selector", Itm.Selector.ToString()); nx.SetAttribute("Selected", Itm.Selected.ToString()); nx.SetAttribute("OnClick", Itm.OnClick); nx.SetAttribute("LoadOnExpand", Itm.LoadOnExpand.ToString()); myXML.AppendChild(nx); if (Itm.Items.Count > 0) { EncodeNodes(Itm.Items, nx, myXMLobj); } } }
private static void UpdateAppConfig(string config, string binFolder) { Console.WriteLine($"Patching file {config}"); XmlDataDocument xmldoc = new XmlDataDocument(); //Open file with xml using (FileStream fs = new FileStream(config, FileMode.Open, FileAccess.Read)) { xmldoc.Load(fs); } //Remove binding node XmlNamespaceManager ns = new XmlNamespaceManager(xmldoc.NameTable); ns.AddNamespace("ab", "urn:schemas-microsoft-com:asm.v1"); XmlNode assemblyBinding = xmldoc.SelectSingleNode("configuration/runtime/ab:assemblyBinding", ns); if (assemblyBinding != null) { XmlNode tmpruntime = xmldoc.SelectSingleNode("configuration/runtime"); tmpruntime.RemoveChild(assemblyBinding); } else { XmlNode tmpruntime = xmldoc.SelectSingleNode("configuration/runtime"); if (tmpruntime == null) { XmlNode configuration = xmldoc.SelectSingleNode("configuration"); XmlElement runtimeElement = xmldoc.CreateElement("runtime"); configuration.AppendChild(runtimeElement); } } XmlNode runtime = xmldoc.SelectSingleNode("configuration/runtime"); XmlElement assemblyBindingElement = xmldoc.CreateElement("assemblyBinding"); assemblyBindingElement.SetAttribute("xmlns", "urn:schemas-microsoft-com:asm.v1"); //Lets create the assembly's, first load all assembly string[] files = Directory.GetFiles(binFolder, "*.dll"); foreach (var file in files) { Console.WriteLine($"Loading dll file {file}"); var assembly = Assembly.LoadFile(file); string assemblyVersion = assembly.GetName().Version.ToString(); string assemblyName = assembly.GetName().Name; string publicKeyToken = GetPublicKeyTokenFromAssembly(assembly); XmlElement tmpAssemblyBinding = xmldoc.CreateElement("dependentAssembly"); XmlElement tmpAssemblyIdentity = xmldoc.CreateElement("assemblyIdentity"); tmpAssemblyIdentity.SetAttribute("name", assemblyName); if (!string.IsNullOrEmpty(publicKeyToken)) { tmpAssemblyIdentity.SetAttribute("publicKeyToken", publicKeyToken); } XmlElement tmpBindingRedirect = xmldoc.CreateElement("bindingRedirect"); tmpBindingRedirect.SetAttribute("oldVersion", $"0.0.0.0-{assemblyVersion}"); tmpBindingRedirect.SetAttribute("newVersion", assemblyVersion); tmpAssemblyBinding.AppendChild(tmpAssemblyIdentity); tmpAssemblyBinding.AppendChild(tmpBindingRedirect); assemblyBindingElement.AppendChild(tmpAssemblyBinding); } runtime.AppendChild(assemblyBindingElement); xmldoc.Save(config); }
public saveConfig(String fileName) { if (fileName == null || fileName.Equals("")) { path = ".\\" + defaultPath; } else { path = ".\\" + fileName; } try { if (File.Exists(path)) { XmlDoc.Load(path); XmlNode all = XmlDoc.SelectSingleNode("All"); Console.WriteLine(all.ChildNodes.Count); } else { log.writeLog("saveConfig模块:\n配置文件不存在,正在新建文件", log.msgType.warning); XmlElement all = XmlDoc.CreateElement("All"); XmlDoc.AppendChild(all); XmlDoc.Save(path); } } catch { log.writeLog("saveConfig模块:\n未知错误,正在重建文件", log.msgType.warning); Delete(); XmlDoc.DocumentElement.RemoveAllAttributes(); XmlElement all = XmlDoc.CreateElement("All"); try { XmlDoc.AppendChild(all); } catch { } XmlDoc.Save(path); } //catch (XmlException) //{ // log.writeLog("saveConfig模块:\n配置文件损坏,正在重建文件", log.msgType.warning); // XmlElement all = XmlDoc.CreateElement("All"); // XmlDoc.AppendChild(all); // XmlDoc.Save(defaultPath); //} //catch (NullReferenceException) //{ // log.writeLog("saveConfig模块:\n配置文件被篡改导致读取出错,正在重建文件", log.msgType.warning); // XmlDoc.DocumentElement.RemoveAllAttributes(); // XmlElement all= XmlDoc.CreateElement("All"); // XmlDoc.AppendChild(all); // XmlDoc.Save(defaultPath); //} //catch { // log.writeLog("saveConfig模块:\n未知错误,正在重建文件", log.msgType.warning); // XmlElement all = XmlDoc.CreateElement("All"); // XmlDoc.AppendChild(all); // XmlDoc.Save(defaultPath); //} }
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { OracleConnection CnOra = new OracleConnection(conexion_cliente_oracle); OracleCommand cmdAcceso = new OracleCommand("PK_USUARIO.LOGIN_ACCESO", CnOra); OracleDataAdapter da = new OracleDataAdapter(cmdAcceso); PRO.agrega_parametro_sp(da, "o_cursor", OracleType.Cursor, ParameterDirection.Output, ""); PRO.agrega_parametro_sp(da, "i_nombre_usuario", OracleType.NVarChar, ParameterDirection.Input, logSistema.UserName); PRO.agrega_parametro_sp(da, "i_password_usuario", OracleType.NVarChar, ParameterDirection.Input, logSistema.Password); da.SelectCommand.CommandType = CommandType.StoredProcedure; try { CnOra.Open(); } catch (Exception ex) { logSistema.FailureText = "HA OCURRIDO UN ERROR CON LA CONEXION A LA BASES DE DATOS ORACLE = " + ex.Message; } DataSet objDS = new DataSet(); da.Fill(objDS, "USUARIO"); CnOra.Close(); CnOra.Dispose(); try { estado = objDS.Tables["USUARIOS"].Rows[0][6].ToString(); id_perfil = objDS.Tables["USUARIOS"].Rows[0][1].ToString(); nombre = objDS.Tables["USUARIOS"].Rows[0][3].ToString(); id_usuario = objDS.Tables["USUARIOS"].Rows[0][0].ToString(); try { oAddr = new IPAddress(Dns.GetHostByName(Dns.GetHostName()).AddressList[0].Address); mIP = oAddr.ToString(); mIP = Request.ServerVariables["REMOTE_ADDR"].ToString(); } catch (Exception ex) { mIP = "0.0.0.0 " + ex.Message.ToString(); } try { mEquipo = Dns.GetHostName(); mEquipo = Request.ServerVariables["REMOTE_ADDR"].ToString(); } catch (Exception ex) { mEquipo = "EQUIPO DESCONOCIDO " + ex.Message.ToString(); } try { winSession = System.Security.Principal.WindowsIdentity.GetCurrent().Name; } catch (Exception ex) { winSession = "SESION DESCONOCIDA " + ex.Message.ToString(); } descripcion = "INTENTO INGRESAR CON USUARIO DESHABILITADO"; } catch (Exception ex) { } ser = Server.MapPath("./CorreoAlerta.htm"); fecha = DateTime.Now.ToString(); url = "administracion.aspx"; if (estado == "1") { PRO.Insertamos_log(nombre, id_perfil, id_usuario, url, fecha, mEquipo, winSession, mIP, descripcion); PRO.EnviarAlerta(ser, nombre, id_perfil, id_usuario, url, fecha, mEquipo, winSession, mIP, descripcion); } if ((objDS.Tables["USUARIO"].Rows.Count == 0) || estado == "1") { logSistema.UserNameRequiredErrorMessage = "Usuario Incorrecto"; logSistema.PasswordRequiredErrorMessage = "Password Incorrecto"; } else { XmlDataDocument xml_session = new XmlDataDocument(); XmlNode NODO_RAIZ, NODO_USUARIO, Nodo_iduser, Nodo_idperfil, Nodo_username, Nodo_nombre, Nodo_idempresa, nodo_nomEmpresa; xml_session.LoadXml("<SESSION></SESSION>"); NODO_RAIZ = xml_session.SelectSingleNode("SESSION"); NODO_USUARIO = xml_session.CreateElement("DATOS_USUARIO"); NODO_RAIZ.AppendChild(NODO_USUARIO); Nodo_iduser = xml_session.CreateElement("ID_USUARIO"); Nodo_iduser.InnerText = objDS.Tables["USUARIO"].Rows[0][0].ToString(); //ID_usuario Nodo_idperfil = xml_session.CreateElement("ID_PERFIL"); lb_id_usuario.Text = objDS.Tables["USUARIO"].Rows[0][0].ToString(); Nodo_idperfil.InnerText = objDS.Tables["USUARIO"].Rows[0][1].ToString(); //'ID_PERFIL Nodo_username = xml_session.CreateElement("USERNAME"); Nodo_username.InnerText = objDS.Tables["USUARIO"].Rows[0][2].ToString(); Nodo_nombre = xml_session.CreateElement("NOMBRE"); Nodo_nombre.InnerText = objDS.Tables["USUARIO"].Rows[0][3].ToString(); Nodo_idempresa = xml_session.CreateElement("RUT_EMPRESA"); Nodo_idempresa.InnerText = objDS.Tables["USUARIO"].Rows[0][4].ToString(); //'RUT_EMPRESA lb_rut_empresa.Text = objDS.Tables["USUARIO"].Rows[0][4].ToString(); nodo_nomEmpresa = xml_session.CreateElement("NOMBRE_EMPRESA"); nodo_nomEmpresa.InnerText = objDS.Tables["USUARIO"].Rows[0][5].ToString(); NODO_USUARIO.AppendChild(Nodo_iduser); NODO_USUARIO.AppendChild(Nodo_idperfil); NODO_USUARIO.AppendChild(Nodo_username); NODO_USUARIO.AppendChild(Nodo_nombre); NODO_USUARIO.AppendChild(Nodo_idempresa); NODO_USUARIO.AppendChild(nodo_nomEmpresa); try{ xml_session.Save(Server.MapPath("./sessiones/") + "usuario_" + Session.SessionID + ".xml"); descripcion = "INGRESO CON USUARIO HABILITADO"; PRO.Insertamos_log(nombre, id_perfil, id_usuario, url, fecha, mEquipo, winSession, mIP, descripcion); //'*********************** INSERTAMOS LOG DEL SISTEMA *********************************** try{ String str_fecha, str_hora, str_min, str_desc_evento; str_fecha = DateTime.Now.Date.ToString(); str_hora = DateTime.Now.Hour.ToString(); str_min = DateTime.Now.Minute.ToString(); str_hora = str_hora + ":" + str_min; str_desc_evento = "INICIO DE SESION DE USUARIO DESDE LA IP CLIENTE: " + Request.ServerVariables["REMOTE_ADDR"].ToString(); PRO.inserta_log_sistema(lb_id_usuario.Text, lb_rut_empresa.Text, str_fecha, str_hora, str_desc_evento, "0", "0", Request.ServerVariables["REMOTE_ADDR"].ToString()); }catch (Exception ex) { Response.Write("Error al grabar XML de session" + ex.Message); Response.End(); } //'************************************************************************************** } catch (Exception ex) { Response.Write("Error al grabar XML de session" + ex.Message); Response.End(); } String plataformaSTR; plataformaSTR = Request.Browser.Type; if (plataformaSTR != "IE7") { Response.Redirect("inicio.aspx"); } else { Response.Redirect("inicio.aspx"); } } }
public void TestCreateElementAndRow() { DataSet ds = new DataSet("set"); DataTable dt = new DataTable("tab1"); dt.Columns.Add("col1"); dt.Columns.Add("col2"); ds.Tables.Add(dt); DataTable dt2 = new DataTable("child"); dt2.Columns.Add("ref"); dt2.Columns.Add("val"); ds.Tables.Add(dt2); DataRelation rel = new DataRelation("rel", dt.Columns [0], dt2.Columns [0]); rel.Nested = true; ds.Relations.Add(rel); XmlDataDocument doc = new XmlDataDocument(ds); doc.LoadXml("<set><tab1><col1>1</col1><col2/><child><ref>1</ref><val>aaa</val></child></tab1></set>"); AssertEquals(1, ds.Tables [0].Rows.Count); AssertEquals(1, ds.Tables [1].Rows.Count); // document element - no mapped row XmlElement el = doc.DocumentElement; AssertNull(doc.GetRowFromElement(el)); // tab1 element - has mapped row el = el.FirstChild as XmlElement; DataRow row = doc.GetRowFromElement(el); AssertNotNull(row); AssertEquals(DataRowState.Added, row.RowState); // col1 - it is column. no mapped row el = el.FirstChild as XmlElement; row = doc.GetRowFromElement(el); AssertNull(row); // col2 - it is column. np mapped row el = el.NextSibling as XmlElement; row = doc.GetRowFromElement(el); AssertNull(row); // child - has mapped row el = el.NextSibling as XmlElement; row = doc.GetRowFromElement(el); AssertNotNull(row); AssertEquals(DataRowState.Added, row.RowState); // created (detached) table 1 element (used later) el = doc.CreateElement("tab1"); row = doc.GetRowFromElement(el); AssertEquals(DataRowState.Detached, row.RowState); AssertEquals(1, dt.Rows.Count); // not added yet // adding a node before setting EnforceConstraints // raises an error try { doc.DocumentElement.AppendChild(el); Fail("Invalid Operation should occur; EnforceConstraints prevents addition."); } catch (InvalidOperationException) { } // try again... ds.EnforceConstraints = false; AssertEquals(1, dt.Rows.Count); // not added yet doc.DocumentElement.AppendChild(el); AssertEquals(2, dt.Rows.Count); // added row = doc.GetRowFromElement(el); AssertEquals(DataRowState.Added, row.RowState); // changed // Irrelevant element XmlElement el2 = doc.CreateElement("hoge"); row = doc.GetRowFromElement(el2); AssertNull(row); // created table 2 element (used later) el = doc.CreateElement("child"); row = doc.GetRowFromElement(el); AssertEquals(DataRowState.Detached, row.RowState); // Adding it to irrelevant element performs no row state change. AssertEquals(1, dt2.Rows.Count); // not added yet el2.AppendChild(el); AssertEquals(1, dt2.Rows.Count); // still not added row = doc.GetRowFromElement(el); AssertEquals(DataRowState.Detached, row.RowState); // still detached here }