Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 4th, 2006, 02:15 PM
Kürşat
Guest
 
Posts: n/a
Default Flat searching in XML document

Hi all,

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?


  #2  
Old August 4th, 2006, 02:45 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: Flat searching in XML document



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/
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles