473,698 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlNodeReader.S kip Method not working as expected

23 New Member
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
Expand|Select|Wrap|Line Numbers
  1. <a id="HyperLink1" href="jsisland.htm" >NEXT</a>
  2. <a id="HyperLink2" href="framset.htm" class="pop" >gotoframeset</a>
  3.  
  4. <div id="Div1" style="DISPLAY: none">
  5.    <a>first</a>
  6.    <a1>second</a>
  7. </div>
  8.  
  9. <a3 id ="Div2" style="VISIBILITY: hidden "> includeme</a3>
  10.  
My code
Expand|Select|Wrap|Line Numbers
  1.              XmlDocument xDoc = new XmlDocument();
  2.             xDoc.LoadXml(xmldoc);
  3.             XmlNodeReader reader = new XmlNodeReader(xDoc);
  4.  
  5.             while (!reader.EOF)
  6.             {
  7.  
  8.                     reader.Read();
  9.                     XmlNodeType nodeType = reader.NodeType;
  10.  
  11.                     if (nodeType == XmlNodeType.Element)
  12.                     {
  13.                         if (reader.HasAttributes)
  14.                         {
  15.  
  16.                             for (int i1 = 0; i1 < reader.AttributeCount; i1++)
  17.                             {
  18.                                 reader.MoveToAttribute(i1);
  19.                                  switch (reader.Name)
  20.                                 {
  21.                                     case "style":
  22.                                        if (reader.Value.Contains("VISIBILITY: hidden") || (reader.Value.Contains("DISPLAY: none")))
  23.                                         {
  24.                                             reader.Skip();
  25.                                         }
  26.  
  27.                                         break;
  28.                                 }
  29.                             }
  30.  
  31.                         }
  32.                     }
  33.                     else if (nodeType == XmlNodeType.Text)
  34.                     {
  35.  
  36.                         Console.WriteLine("other" + reader.Value.ToString()); 
  37.                         Console.ReadLine();
  38.                     }
  39.  
  40.            } //end while
  41.  
Can any one help me with this

Thank You.
Jan 2 '08 #1
10 1664
Plater
7,872 Recognized Expert Expert
Seems to me your code is doing exactly what it should do.
You tell it to skip nodes that have visibility:hidd en or Display:none
So it skips your <div> and <a3> tag.
And arrives at the text tag "includeme" which it is told to print out.
Although I would also expect it to print out "other first" and "other second" too. (According to your console.writeli ne() )

EDIT: On that note, I would think it would print out the whitespace you have in the file too.
Jan 2 '08 #2
jambalapamba
23 New Member
Seems to me your code is doing exactly what it should do.
You tell it to skip nodes that have visibility:hidd en or Display:none
So it skips your <div> and <a3> tag.
And arrives at the text tag "includeme" which it is told to print out.
Although I would also expect it to print out "other first" and "other second" too. (According to your console.writeli ne() )

EDIT: On that note, I would think it would print out the whitespace you have in the file too.

Its printing "other first" and "other second" but i want to skip "includeme" as well because its element value of <a3> tag which i want to skip all the child nodes inside <a3> element.
Jan 3 '08 #3
Plater
7,872 Recognized Expert Expert
Its printing "other first" and "other second" but i want to skip "includeme" as well because its element value of <a3> tag which i want to skip all the child nodes inside <a3> element.
Well that's not the code you have written, you're not skipping the "first" and "second" nodes either, even though they are children of the <div> tag that should be skipped.
I think you need to go to next sibbling, and not next child. Not sure if "tree logic" is correct here, but it seems like "skip" just moves to the next node, regardless of if it's a child or a sibbling (or even a step back "up")
Jan 3 '08 #4
jambalapamba
23 New Member
I am really sorry skip method skips entire element my code is not displaying "first" and "second". The skip method skips entire element and its children as well.
Jan 3 '08 #5
Plater
7,872 Recognized Expert Expert
Will it skip correctly if you do this with your existing code?
Expand|Select|Wrap|Line Numbers
  1. <a3 id ="Div2" style="VISIBILITY: hidden "><sometag> includeme</sometag></a3>
  2.  
Jan 3 '08 #6
jambalapamba
23 New Member
no its not because its not reading <a3> only if it reads a3 then it goes in to the
nodetype.elemen t loop and skips it, but the problem is its not reading <a3> it is going to the value. Everytime i skip an element its not reading next element tag its reading the value.
Jan 3 '08 #7
Plater
7,872 Recognized Expert Expert
Are you going to next AND skip?
Jan 3 '08 #8
jambalapamba
23 New Member
when ever i find style attribute in a element with the condition hidden i will be skipping that entire element and i will be reading next node
Jan 3 '08 #9
Plater
7,872 Recognized Expert Expert
But if you .Skip() (going to next node) and then .Next(), you are moving twice?
Jan 3 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

10
3559
by: John Brock | last post by:
I have a base class with several derived classes (I'm writing in VB.NET). I want each derived class to have a unique class ID (a String), and I want the derived classes to inherit from the base class *Shared* methods which make use of the class ID. So I gave the base class a classID field, and then I gave the derived classes Shared constructors, which I used to set the classID field to the appropriate values for each derived class. But...
0
1261
by: Brian Rogers | last post by:
To whom it may concern: Can anyone explain this behaviour in serialization and deserialization? I serialize an object using an XML serializer. I de-serialize the object from a StringReader and it deserializes correctly I de-serialize the object from a XmlNodeReader and it deserializes incorrectly. The xml code contained in the StringReader and XmlNodeReader is IDENTICLE.
4
11387
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This should have worked fine since the class in question was already being serialized and deserialized as part of a Web service interface. What I found was that by deserializing from an XmlNodeReader instead of an XmlTextReader, XML Serialization doesn't work...
1
2589
by: Kris Desmadryl | last post by:
I want to loop all nodes of an xml file, because I want to search the content for a certain search pattern. I did something like this : reader = New XmlNodeReader(doc) While reader.Read() Select Case reader.NodeType Case XmlNodeType.Element Select Case reader.Name Case "al" Dim value As String
59
6855
by: AK | last post by:
I tried to google "skip scan DB2" but came up with nothing. Does DB2 have the feature under a different name?
4
4699
by: David | last post by:
All I have an XML document as illustrated in the extract below. I am trying to use the XmlNodeReader to extract information from the document. What I am having trouble with is when I read the line of the document I am unable to read the value of the element. Below is an extract of the source code that I am using to read the other parts of the document that I want to extract. Any assistance would be appreciated. Thanks
4
3568
by: Samuel R. Neff | last post by:
I'm deserializing an XML file. If I pass a Stream to the file directly to the deserializer as follows it works fine: o = (New XmlSerializer( GetType( CompensationPackage))).Deserialize(stream) But if I pass an XmlNodeReader to the deserializer it doesn't work:
3
1525
by: adhag | last post by:
Hi I am trying to parse through a large file in pieces using the xmlNodeReader. I only need it to be forward only and performance is the key but I am having a problem trying to get all the information out of my xml file. For arguments sake my sample xml file looks like this <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?> <row value="123"> <errorcol e_w_flag="e" value="10003" col="5"/>
1
1916
by: WalterWalt | last post by:
Below is a part of my xml file returned from a webservice. Instead of converting to a datatable and going through it a record at a time checking if ClientCodeType = "Balloon_Type" and ClientCode = "R" to the OurCode of 3, I want to use the XMLNodeReader to get that result back using MoveTo.. functions. My first of probably many question is how come this XMLNodeReader has no attributes. I can not change the way the webservice returns the...
0
8680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9030
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6528
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.