brian_dallas
asked on
How to Rename an XmlNode and all its Children
I'm trying to figure out the best way to rename an element and all of its children. For example, I would like to prepend or append arbitrary text to distinguish the node (and its children) for use in a DataSet. The code below is in .NET. The place I'm having a problem is noted below. Is there a better way to do this, XSLT perhaps?
BTW: I have to do this in C# .NET, so DOM3 isn't an option.
private void ProcessChildren(XmlNode xnod, int Depth)
{
if ((xnod.NodeType == XmlNodeType.Element))
{
// WHAT DO I DO HERE TO RENAME THE CURRENT NODE???
// Process the children of this node
XmlNode xnodworking;
if (xnod.HasChildNodes)
{
xnodworking = xnod.FirstChild;
while(xnodworking != null)
{
ProcessChildren(xnodworkin g, Depth + 1);
xnodworking = xnodworking.NextSibling;
}
}
}
}
private XmlNode RenameNodes(System.Xml.Xml Node rs_node)
{
XmlNode xnodWorking;
if (rs_node.HasChildNodes)
{
xnodWorking = rs_node.FirstChild;
while(xnodWorking != null)
{
ProcessChildren(xnodWorkin g, 0);
xnodWorking = xnodWorking.NextSibling;
}
}
return null;
}
Thanks.
BTW: I have to do this in C# .NET, so DOM3 isn't an option.
private void ProcessChildren(XmlNode xnod, int Depth)
{
if ((xnod.NodeType == XmlNodeType.Element))
{
// WHAT DO I DO HERE TO RENAME THE CURRENT NODE???
// Process the children of this node
XmlNode xnodworking;
if (xnod.HasChildNodes)
{
xnodworking = xnod.FirstChild;
while(xnodworking != null)
{
ProcessChildren(xnodworkin
xnodworking = xnodworking.NextSibling;
}
}
}
}
private XmlNode RenameNodes(System.Xml.Xml
{
XmlNode xnodWorking;
if (rs_node.HasChildNodes)
{
xnodWorking = rs_node.FirstChild;
while(xnodWorking != null)
{
ProcessChildren(xnodWorkin
xnodWorking = xnodWorking.NextSibling;
}
}
return null;
}
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.