本文介绍了如何检查xml文件中是否可用的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这段代码不是我的 r ,可以帮我看看这段代码需要添加一些东西吗?因为我的问题是如何检查xml文件中可用的ID是否为


  protected void Button3_Click(object sender,EventArgs e)

    {

        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

        doc.Load(Server.MapPath(" Inventory.xml"));;


       

        if(TextBox1.Text.Equals(""))

        {

            Label1.Visible = true;

            Label1.Text =" Please write Id"; $
           返回;

        }
       否则为
        {

        }
        if(!System.IO.File.Exists(Server.MapPath(TextBox1.Text +" Inventory.xml"))))b
        {

            Label1.Visible = true;

            Label1.Text =" ID available";

           返回;

        }
       否则为
        {

            Label1.Visible = true;

            Label1.Text ="使用的ID,请重写" ;;

            TextBox1.Text ="" ;;

           返回;
$
            

        }
    }


我的xml文件


< products>

  < cloths id =" A01">

    < clothName> Polo Shirt< / clothName>

    <尺寸> S< /尺寸>

    <价格> 50.99< / Price>

    <金额> 100000< /金额>

    < images>图片/ shirt1.png< / images>

  < / cloths>

  < cloths id =" A02">

    < clothName> Polo Shirt< / clothName>

    <尺寸> M< /尺寸>

    <价格> 50.99< / Price>

    <金额> 100000< /金额>

    < images>图片/ shirt1.png< / images>

  < / cloths>

  < cloths id =" A03">

    < clothName> Polo Shirt< / clothName>

    <尺寸> XL< /尺寸>

    <价格> 50.99< / Price>

    <金额> 100000< /金额>

    < images>图片/ shirt1.png< / images>

  < / cloths>


< / products>

解决方案


this code is not working, can help me see this code need to add somethings? because my problem is how to check the id available or not in xml file

 protected void Button3_Click(object sender, EventArgs e)
    {
        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
        doc.Load(Server.MapPath("Inventory.xml"));

       
        if (TextBox1.Text.Equals(""))
        {
            Label1.Visible = true;
            Label1.Text = "Please write Id";
            return;
        }
        else
        {
        }
        if (!System.IO.File.Exists(Server.MapPath(TextBox1.Text + "Inventory.xml")))
        {
            Label1.Visible = true;
            Label1.Text = "ID available";
            return;
        }
        else
        {
            Label1.Visible = true;
            Label1.Text = "ID used, please rewrite";
            TextBox1.Text = "";
            return;
            
        }
    }

my xml file

<products>
  <cloths id="A01">
    <clothName>Polo Shirt</clothName>
    <Size>S</Size>
    <Price>50.99</Price>
    <Amount>100000</Amount>
    <images>Image/shirt1.png</images>
  </cloths>
  <cloths id="A02">
    <clothName>Polo Shirt</clothName>
    <Size>M</Size>
    <Price>50.99</Price>
    <Amount>100000</Amount>
    <images>Image/shirt1.png</images>
  </cloths>
  <cloths id="A03">
    <clothName>Polo Shirt</clothName>
    <Size>XL</Size>
    <Price>50.99</Price>
    <Amount>100000</Amount>
    <images>Image/shirt1.png</images>
  </cloths>

</products>

解决方案


这篇关于如何检查xml文件中是否可用的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 11:53
查看更多