I am trying to skip element in xml document where style attribute is VISIBILITY: hidden or DISPLAY: none.
In the following example i want to skip the last two elements but when i skip the element with id=”Div1”
and next reader.Read() reads “ includeme” but i expected it to read element <a id ="Div2" style="visibili ty:hidden "> and skip it instead its writing “ includeme” to the console
sample xml
[code=xml]
<a id="HyperLink1 " href="jsisland. htm" >NEXT</a>
<a id="HyperLink2 " href="framset.h tm" class="pop" >gotoframeset </a>
<div id="Div1" style="DISPLAY: none">
<a>first</a>
<a1>second</a>
</div>
<a3 id ="Div2" style="VISIBILI TY: hidden "> includeme</a3>
[/code]
My code
Can any one help me with this
Thank You.
In the following example i want to skip the last two elements but when i skip the element with id=”Div1”
and next reader.Read() reads “ includeme” but i expected it to read element <a id ="Div2" style="visibili ty:hidden "> and skip it instead its writing “ includeme” to the console
sample xml
[code=xml]
<a id="HyperLink1 " href="jsisland. htm" >NEXT</a>
<a id="HyperLink2 " href="framset.h tm" class="pop" >gotoframeset </a>
<div id="Div1" style="DISPLAY: none">
<a>first</a>
<a1>second</a>
</div>
<a3 id ="Div2" style="VISIBILI TY: hidden "> includeme</a3>
[/code]
My code
Code:
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(xmldoc);
XmlNodeReader reader = new XmlNodeReader(xDoc);
while (!reader.EOF)
{
reader.Read();
XmlNodeType nodeType = reader.NodeType;
if (nodeType == XmlNodeType.Element)
{
if (reader.HasAttributes)
{
for (int i1 = 0; i1 < reader.AttributeCount; i1++)
{
reader.MoveToAttribute(i1);
switch (reader.Name)
{
case "style":
if (reader.Value.Contains("VISIBILITY: hidden") || (reader.Value.Contains("DISPLAY: none")))
{
reader.Skip();
}
break;
}
}
}
}
else if (nodeType == XmlNodeType.Text)
{
Console.WriteLine("other" + reader.Value.ToString());
Console.ReadLine();
}
} //end while
Thank You.
Comment