-
Jan 24th, 2023, 10:54 AM
#1
Thread Starter
Fanatic Member
Remove XML Nodes
Hi All,
What is the easiest option to remove XML Nodes? I want to convert an XML document to a comma separated document?
I would basically delete the opening nodes, and replacing the closing nodes with a comma.
This is because I need to write a Proof Of Concept app, and quite frankly trying to make it work with a raw XML document is not my strength
"Wisdom is only truly achieved, when you realise you dont know everything" ... I must be a genius because I always have to ask stupid questions...
Pointing an idiot like me in the right direction, is always appreciated by the idiot, explaining how to do what you have pointed the idiot to, is appreciated even more. I apologise to all experienced coders who will think I am an idiot, you are right, I am an idiot, but I am an idiot who is trying to learn
-
Jan 24th, 2023, 11:04 AM
#2
Addicted Member
Re: Remove XML Nodes
Personally I would check out the DaytaSet/DataTable.ReadXML method, once the data is in a datatable there's plenty of options to output to CSV
-
Jan 24th, 2023, 11:18 AM
#3
Re: Remove XML Nodes
Since you didn't show the XML ...
Code:
Dim foo As XElement
' foo = XElement.Load("path here")
' for test use literal
' 5 rows, 3 cols
foo = <root>
<%= From r In Enumerable.Range(1, 5)
Select <row>
<%= From c In Enumerable.Range(1, 3)
Select <col><%= r.ToString & " " & c.ToString %></col>
%>
</row>
%>
</root>
'<root>
' <row>
' <col>1 1</col>
' <col>1 2</col>
' <col>1 3</col>
' </row>
' <row>
' <col>2 1</col>
' <col>2 2</col>
' <col>2 3</col>
' </row>
' <row>
' <col>3 1</col>
' <col>3 2</col>
' <col>3 3</col>
' </row>
' <row>
' <col>4 1</col>
' <col>4 2</col>
' <col>4 3</col>
' </row>
' <row>
' <col>5 1</col>
' <col>5 2</col>
' <col>5 3</col>
' </row>
'</root>
Convert the above to CSV
Code:
Dim sb As New System.Text.StringBuilder
For Each r As XElement In foo.Elements
For Each c As XElement In r.Elements
sb.Append(c.Value)
sb.Append(", ")
Next
sb.Length -= 2
sb.AppendLine()
Next
Debug.WriteLine(sb.ToString)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|