Adding attribute to the parentnode of text node

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jambalapamba
    New Member
    • Nov 2007
    • 23

    Adding attribute to the parentnode of text node

    Hi

    I am walking xml using c# and i want add attribute (style="text-decoration: line-through;" ) to the parent node of text node if the value meets some condition.

    e.g if this element <div >include</div> as include doesn't contain "read" i want <div style="text-decoration: line-through;">inclu de</div>

    Here is wht i am doing

    XmlDocument xDoc = new XmlDocument();
    xDoc.LoadXml(xm ldoc);
    XmlNodeReader reader = new XmlNodeReader(x Doc);
    while (!reader.EOF)
    {

    reader.Read();
    XmlNodeType nodeType = reader.NodeType ;

    Console.WriteLi ne(reader.Value );
    if (nodeType == XmlNodeType.Ele ment)
    {
    for (int i = 0; i < reader.Attribut eCount; i++)
    {
    //do something
    }

    }
    else if (nodeType == XmlNodeType.Tex t)
    {
    if (reader.Value.T oString().Conta ins("read"))
    {
    //do something
    }
    else
    {
    //i want to add attribute to the parent element of this text node
    }
    }

    } //end while



    Can any one give me suggestiongs how to do it



    Thank you
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    First off, you probably shouldn't be using an XmlReader which is a read-only class. Is it possible for you to use something else, or is your code deeply routed in this?

    Comment

    Working...