HighTechTalks DotNet Forums  

Re: Flat searching in XML document

Dotnet XML microsoft.public.dotnet.xml


Discuss Re: Flat searching in XML document in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Martin Honnen
 
Posts: n/a

Default Re: Flat searching in XML document - 08-04-2006 , 08:47 AM








Kürşat wrote:


Quote:
I want to write a class which define some frequent XML operations. For
example a method named "getElementByAttribute (string attrName, string
attrVal)" should return an XmlElement object which includes first element in
the document which has same attribute name and value as method parameters
define. Is there any easy way of this other than recursively scan nodes of
document?
Well the DOM implementation in .NET has XPath supports with SelectNodes
and SelectSingleNode meaning many such tasks like the one described
above could be "implementing" by delegating to a SelectSingleNode call
with the proper XPath expression e.g.
SelectSingleNode("//*[@" + attrName + " = '" + attrValue + "']")
In reality you have some more work to prevent errors when e.g. attrValue
contains a single quote '. But I hope you get the idea.
There is of course also the problem with XML with namespaces where the
attribute name could be a qualified name with prefix, colon, and local
name, if you really want to solve that in general then you need to take
that into account as well.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.