tags:

views:

45

answers:

1

I have an XML document which contains nodes like following:-

<a class="custom">test</a>
<a class="xyz"></a>

I was tryng to get the nodes for which class is NOT "Custom" and I wrote an expression like following:-

XmlNodeList nodeList = document.SelectNodes("//*[self::A[@class!='custom'] or self::a[@class!='custom']]"); 

Now, I want to get IMG tags as well and I want to add the following experession as well to the above expression:-

//*[self::IMG or self::img]

...so that I get all the IMG nodes as well and any tag other than having "custom" as value in the class attribute.

Any help will be appreciated.

EDIT :- I tried the following and this is an invalid syntax as this returns a boolean and not any nodelist:-

 XmlNodeList nodeList = document.SelectNodes("//*[self::A[@class!='custom'] or self::a[@class!='custom']] && [self::IMG or self::img]"); 
+2  A: 

Not sure of what you are asking, but have you tried something like the following?

  "//A[@class!='custom'] | //a[@class!='custom'] | //IMG | //img"
baol
@Baol, Thanl you for your time. However, this does not work. This expression does not even select the nodes which dont have "custom" as the attribute value. My first XPath works for that atleast.
ydobonmai
I edited it a few seconds after having posted it after having tested it using an XSL sheet. When used in a <xsl:apply-templates> statement it has worked fine. Can you post a larger snippet of the XML?
baol
That should work just fine. I created a simple XML document and it grabbed the expected nodes.
Tom
baol
@Baol, Thank you very much. The comment above by me was for the expression when you posted for the first time. the edited one works well.
ydobonmai