English 中文(简体)
要素。 移除(XNode.Remove)
原标题:XElement.Remove (XNode.Remove) doesn t work

Im试图将个人节点从母子中删除,我尝试了Remove 方法,但似乎还在使用。 如何做到这一点? 这难道是一种ug吗?

Sub Main()
  Dim xml =
    <?xml version="1.0" encoding="utf-8"?>
    <Products>
      <Product name="ABC-1" link="http://www.site.com/1"/>
      <Product name="ABC-2" link="http://www.site.com/2"/>
      <Product name="ABC-3" link="http://www.site.com/3"/>
    </Products>

  Dim products = xml.Root.<Product>

   works - uncomment
   products.Remove()

   Doesn t work
  For Each product In products
    product.Remove()
  Next

  xml.Save(FailedFilename)
End Sub
最佳回答

在超过<条码>产品时删除节点,导致修改。 缩略语 缩略语 为此,仅需在<条码>上添加一个电话:ToArray(或ToList():

For Each product In products.ToArray()
    product.Remove()
Next

注:以上等于以下刀切。 在宣布<条码>产品/代码>时添加<条码>。 变量:

Dim temp = products.ToArray()
For Each product In temp
    product.Remove()
Next

页: 1

除非在删除之前需要与每一条<代码><>product/code>合作,否则使用Remove分机/a>。

问题回答

暂无回答




相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签