473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Replace All XML Data

For testing purposes, I need some code that will loop through all attributes
and elements in an XML file, and replace the data with the element or
attribute name? Does anybody have code that will do this, looping
generically through every node? VB.Net code would be appreciated so I can
see how it is done.

Derek
Aug 19 '06 #1
4 1790
Hello Derek,

You could use a recursive function that operated on XmlNode objects (see
XmlNode in MSDN docs or Object Browser). Or you could use an XmlReader and
process each node as it was streamed in. I really have no experience using
XmlNavigator or XmlReader.. so I can only speak about the XmlNode method.

I'll outline the process in pseudo code.. you can give it a shot from there.

Load the XML into an XmlDocument
Pass the root node to the recursive function

The recursive function will take an XmlNode as input.
Function guts:
Process node (read all attributes; read node text)
For each childNode in inputNode.ChildNodes
pass childnode to function
End For
End Function

Enjoy,
-Boo

For testing purposes, I need some code that will loop through all
attributes and elements in an XML file, and replace the data with the
element or attribute name? Does anybody have code that will do this,
looping generically through every node? VB.Net code would be
appreciated so I can see how it is done.

Derek

Aug 19 '06 #2
Does anybody have code for this?
"GhostInAK" <gh*******@gmail.comwrote in message
news:c7**************************@news.microsoft.c om...
Hello Derek,

You could use a recursive function that operated on XmlNode objects (see
XmlNode in MSDN docs or Object Browser). Or you could use an XmlReader
and process each node as it was streamed in. I really have no experience
using XmlNavigator or XmlReader.. so I can only speak about the XmlNode
method.

I'll outline the process in pseudo code.. you can give it a shot from
there.

Load the XML into an XmlDocument
Pass the root node to the recursive function

The recursive function will take an XmlNode as input.
Function guts:
Process node (read all attributes; read node text)
For each childNode in inputNode.ChildNodes
pass childnode to function
End For
End Function

Enjoy,
-Boo

>For testing purposes, I need some code that will loop through all
attributes and elements in an XML file, and replace the data with the
element or attribute name? Does anybody have code that will do this,
looping generically through every node? VB.Net code would be
appreciated so I can see how it is done.

Derek


Aug 19 '06 #3
Derek,

I doubt if anybody will have code for this specific question of you.

However this is code that shows easily how to use the node reader maybe you
can expiriment with the most inner part in the loop.

\\\\
Dim xmlString As String = "<department>" & _
"<employee name=""ABC"" age=""31"" sex=""male""/>" & _
"<employee name=""CDE"" age=""40"" sex=""male""/></department>"
Dim sr As New System.IO.StringReader(xmlString)
Dim doc As New Xml.XmlDocument
doc.Load(sr)
'or just in this case doc.LoadXML(xmlString)
Dim reader As New Xml.XmlNodeReader(doc)
While reader.Read()
Select Case reader.NodeType
Case Xml.XmlNodeType.Element
If reader.Name = "employee" Then
MessageBox.Show(reader.GetAttribute("name"))
End If
End Select
End While
///

I hope this helps,

Cor
"Derek Hart" <de********@yahoo.comschreef in bericht
news:OI**************@TK2MSFTNGP04.phx.gbl...
Does anybody have code for this?
"GhostInAK" <gh*******@gmail.comwrote in message
news:c7**************************@news.microsoft.c om...
>Hello Derek,

You could use a recursive function that operated on XmlNode objects (see
XmlNode in MSDN docs or Object Browser). Or you could use an XmlReader
and process each node as it was streamed in. I really have no experience
using XmlNavigator or XmlReader.. so I can only speak about the XmlNode
method.

I'll outline the process in pseudo code.. you can give it a shot from
there.

Load the XML into an XmlDocument
Pass the root node to the recursive function

The recursive function will take an XmlNode as input.
Function guts:
Process node (read all attributes; read node text)
For each childNode in inputNode.ChildNodes
pass childnode to function
End For
End Function

Enjoy,
-Boo

>>For testing purposes, I need some code that will loop through all
attributes and elements in an XML file, and replace the data with the
element or attribute name? Does anybody have code that will do this,
looping generically through every node? VB.Net code would be
appreciated so I can see how it is done.

Derek



Aug 19 '06 #4


Derek Hart wrote:
For testing purposes, I need some code that will loop through all attributes
and elements in an XML file, and replace the data with the element or
attribute name? Does anybody have code that will do this, looping
generically through every node? VB.Net code would be appreciated so I can
see how it is done.
An XSLT stylesheet could do that. However your requirement is not clear,
what do you want to do with an element that contains other elements e.g.
<root>
<child>
<descendant>Kibology</descendant>
</child>
</root>
what should happen with the root and the child element do you want e.g.
<root>root
<child>child
<descendant>descendant</descendant>
</child>
</root>
or do you only want to output the element name of elements not having
any child elements e.g. for the example get
<root>
<child>
<descendant>descendant</descendant>
</child>
</root>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 19 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: hokieghal99 | last post by:
import os, string print " " setpath = raw_input("Enter the path: ") def find_replace(setpath): for root, dirs, files in os.walk(setpath): fname = files for fname in files: find =...
19
by: rbt | last post by:
Here's the scenario: You have many hundred gigabytes of data... possible even a terabyte or two. Within this data, you have private, sensitive information (US social security numbers) about your...
1
by: Luke Dalessandro | last post by:
I have an application where there is a primary XML data file. I'll use the following as an example: <data> <item id="a"> <name>A</name> <price>$10</price> </item> <item id="b">...
2
by: JHB | last post by:
Hi, How can I do a location.replace when I use a form, like when I use a href? This works. <a href="Ny HTML-side20.htm"; method="post" id="frm" name="BrugerHovedSide"...
2
by: Daniel | last post by:
I use an Access database to basically take data exports, import them, manipulate the data, and then turn them into exportable reports. I do this using numerous macros, and queries to get the data...
2
by: jason | last post by:
Hello. I just converted some data to to sql2000 into a TEXT type field. I needed to remove all tabs from the data and now want to remove extra lines too. As we know, SQL2000's replace function...
4
by: Neo Geshel | last post by:
Greetings I am using VB in my ASP.NET project that uses an admin web site to populate a database that provides content for a front end web site. I am looking for a way to use replace() to...
4
by: Roy | last post by:
Hey all, Created an .aspx page using VB as the code behind. Compiler pops up error: "BC30451: Name 'Replace' is not declared." Essentially, it acts as if Replace is a custom function that needs...
7
by: .... | last post by:
Hi I have an existing function which has a stream object (inmsg.BodyPart.Data). I'm trying to search and replace the stream object in the most efficient way possible This is my attempt below,...
6
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello, I have some XML that is returned to my application from another vendor that I cannot change before it gets to me. I can only alter it after it gets to my application. That being said, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.