不要添加重复的节点 [英] dont add duplicate node

查看:111
本文介绍了不要添加重复的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是一个XML文件,在其中单击按钮时会写一个节点.我想要文本框包含与上一个节点相同的名称,则不将其添加到xml文件中,并且显示错误的新打开的窗口.我该怎么做.

请帮助我.

在此先感谢

hi guys,

i am an xml file in which i write a node on button click. i want if textbox contain a same name as a previous node it doesnot add in xml file and it show a error new open window. how can i do this.

please help me in this.

thanks in advance

推荐答案



在这里我根据您的要求编写了一些代码.请尝试

我的xml文件包含以下代码

Hi,

Here I wrote some code for your requirement.try this

My xml file contains following code

<animal>
	<cat>
		<fat_cat>dfgfd</fat_cat>
		<slim_cat>dfgfgfgfgdf</slim_cat>
	</cat>
	<dog>
		<fat_dog>dfgffgdfgd</fat_dog>
		<slim_dog>tytryt</slim_dog>
	</dog>
</animal>



并且由于您的需求设计页面包含文本框和按钮
我使用了一个div标签来显示结果,您可以使用jquery在另一个窗口中显示结果



And as your requirement design page contains textbox and button
and I took one div tag for displaying reults you can use jquery for showing results in another window

<asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown"></asp:textbox><br />
     <asp:button id="Button2" runat="server" text="Button" onclick="Button2_Click" xmlns:asp="#unknown" />
  <br />
   <div id="resdiv" runat="server"></div>




文件后面的代码在按钮单击事件中包含以下代码




And code behind file contains the following code in button click event

XmlTextReader reader = new XmlTextReader(Server.MapPath("~/SomeFiles") + "/" + "XMLFile4.xml");
reader.WhitespaceHandling = WhitespaceHandling.None;

XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(reader);
XmlNodeList xmlnodeli = xmldoc.GetElementsByTagName(TextBox1 .Text );

if (xmlnodeli.Count > 0)
{
    resdiv.InnerHtml = "tag is already exists";

}
else
{
    resdiv.InnerHtml = "tag is not exists";
}



在上面的代码中,您已经更改了一些代码,例如文件路径,...

根据您的要求.

希望你能理解我写的内容.

最好的所有



In the above code you''ve change some code like filepath,...

as your requirement.

I hope you can understand What I write.

All the Best


在按钮上单击,从XML文件的文本框中查找节点,如果存在,则给出错误消息,否则将节点添加到XML文件.
如果您需要更具体的帮助,请使用改进问题"按钮阐明答案并添加一些代码.
On button click look for node from text box in XML file, if it exist give error message else add node to XML file.

If you want more specific help please clarify your answer and add some code, using the Improve question button.


这篇关于不要添加重复的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆