• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 129
  • Last Modified:

Help with deleting data in fields starting with Field

Hi,

How do you empty all data elements in a table where they include the word "Field" using VB.NET

For example if my table contains
<Root>
<Table>
 <PTM>Field 18</PTM>
    <ETM>Field 19</ETM>
    <CP>Field 20</CP>
    <FCSTM>Field 21</FCSTM>
    <LSTM>Field 22</LSTM>
    <LTST>Field 23</LTST>
</Root>
</Table>

I would like the following results

<Root>
<Table>
 <PTM></PTM>
    <ETM></ETM>
    <CP></CP>
    <FCSTM></FCSTM>
    <LSTM></LSTM>
    <LTST></LTST>
</Root>
</Table>

Thanks,

Victor
0
vcharles
Asked:
vcharles
  • 2
  • 2
1 Solution
 
ste5anSenior DeveloperCommented:
Are we talking about tables or XML?
What kind of table?
0
 
vcharlesAuthor Commented:
It is an xml files.
0
 
Fernando SotoCommented:
Hi Victor;

Try this it should work for you.

'' Load XML Document
Dim xdoc = XDocument.Load("Path-To-XML-File\MyXmlFile.xml")

'' Get a list of Nodes that contain the word Field in its inner text
Dim removeValue = (From n In xdoc.Descendants() _
                   Where n.Value.Contains("Field") AndAlso n.HasElements = False _
                   Select n).ToList()

'' Remove the content from the node
For Each node In removeValue
    node.Value = String.Empty
Next

'' Save the modified documents
xdoc.Save("Path-To-XML-File\MyXmlFileModified.xml")

Open in new window

0
 
vcharlesAuthor Commented:
Thank You!
0
 
Fernando SotoCommented:
Not a problem Victor, glad to help.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now