This is a catch-all for any XML related issues using XML, XDR, XSL/T, etc.
wildcards in attribute values
Hi there, I'm having trouble trying to search nodes by attributes using wildcards in the values. e.g.: <people> <person> <friend name="mister ex"/> <friend name="miss ex"/> <friend name="miss new"/> </person> </people> i want to select all nodes with values containing " ex". Does anyone know how I could get this? Would really help a lot! Thanks in advance!
Code: <!-- I just wanted to try and post in the new system but I am pretty sure this will work --> <xsl:value-of select="//friend[contains(@name,'ex')]"/> <!-- this should find every friend node where the name attribute contains "ex" -->
Oh rats! The xpath syntax is correct: Code: "//friend[contains(@name,'ex')]" for a query; however, it is useless in the context I put it in ("value-of"). Share and enjoy!
Thanks for the hint but in our particular problem it did not help. We have a large xml file and must find names (attributes) containing a certain substring. Would be nice if msxml4 had something like that else we have to search the strings in the code which is much slower... Any other Ideas??
Using msxml4 in vb the code would look something like this: Code: Dim xmlDoc As New MSXML2.DOMDocument Dim xmlNodes As MSXML2.IXMLDOMNodeList xmlDoc.LoadXML "<People><Person><Friend Name=""mister ex""/></Person></People>" Set xmlNodes = xmlDoc.SelectNodes("//Friend[contains(@Name,'ex')]")
Seeing that you are searching for a substring, you might want to take a look at using SAX. You can find information on MSDN. It is an inline processor that is a little more efficient when doing inline searches...
Problem is I'm using the DOM Parser together with 3 other programmers involved in the project and either we find a solution with DOM or we would have to change about 10 applications. Not a nice thing to do... And MSDN says you should use SAX when having memory problems, which we don't and that DOM is faster which is more important to us. If DOM does not support this sort of search we will have to implement it ourselves. Thx.
Is the problem still not solved then?
not the way we wished, that is with a DOM method. we're now searching for all possible nodes and getting the right ones with string compare. It works but its not nice. Unfortunately the code you posted doesn't work... Maybe it only works in VB and not in C++! Bye
The language shouldn't matter (except the syntax would more likely be xmlDoc->SelectNodes("..."); This syntax does require a more current version of the msxml parser. v4 works, v3 might work, v2.x probably won't work. pjp
Now I got it. Man I must be stupid. I was trying it on the selectSingleNode function and there it seems not to work. The function you were talking about, that is selectNodes(), there it works. Thanks a lot PjPark for your help and patience!!!!
The smarter you are, the dumber the mistakes you make. You're welcome. pjp