Connecting Tech Pros Worldwide Help | Site Map

Extracting more than one attribute value

Newbie
 
Join Date: Oct 2009
Posts: 4
#1: 3 Weeks Ago
I have an XML file that looks something like this
Expand|Select|Wrap|Line Numbers
  1. <MyXML>
  2.     <Stuff IDX="1"  Name="Swish" Manufacturer="Grimoto" ParentRef = "0" Ref = "1234567" />
  3.     : More elements
  4.     : More elements
  5.         <Stuff IDX="0"  Name="Swosh" Manufacturer="Grimoto" ParentRef = 1234567" Ref = "9876543" />
  6.         : More elements
  7.         : More elements
  8.         </IDX>
  9.     </IDX>
  10. <MyXML>
In the real file there are more attributes. I have managed to extract the complete Element with ParentRef = "0" using a Linq example I found on this site. Is it possible to extract a list of attributes from an Element in one hit using Linq (for instance the Name and Ref in this example) or do I have to process the Element I have extracted to get the information I want?
best answer - posted by Dormilich
from what I’ve read even Linq uses somehow XPath.

nevertheless, it should be something like
Expand|Select|Wrap|Line Numbers
  1. @name or @ref
  2. @*[name() = 'name' or name() = 'ref']
to name 2 possibilities

maybe the experts in the .NET forum can tell you more when it comes to Linq.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#2: 3 Weeks Ago

re: Extracting more than one attribute value


of course you can get more than one attribute at a time. the question is, if that is favourable for your application.
Newbie
 
Join Date: Oct 2009
Posts: 4
#3: 3 Weeks Ago

re: Extracting more than one attribute value


In the real file there are 34 attributes in the Stuff element. I only want some of them extracted. The parent Id is the is Id other elements in the file that also have to have the same attributes extracted. I suppose my question should have been How do I extract multiple attributes from an Element using Linq? At the moment I think it is the most favourable way for my application.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#4: 3 Weeks Ago

re: Extracting more than one attribute value


sorry, I can’t help you with Linq (I’m not using .NET), only with the XPath.
Newbie
 
Join Date: Oct 2009
Posts: 4
#5: 3 Weeks Ago

re: Extracting more than one attribute value


Thanks Dormilich. What is the XPath approach to my problem?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#6: 3 Weeks Ago

re: Extracting more than one attribute value


from what I’ve read even Linq uses somehow XPath.

nevertheless, it should be something like
Expand|Select|Wrap|Line Numbers
  1. @name or @ref
  2. @*[name() = 'name' or name() = 'ref']
to name 2 possibilities

maybe the experts in the .NET forum can tell you more when it comes to Linq.
Newbie
 
Join Date: Oct 2009
Posts: 4
#7: 3 Weeks Ago

re: Extracting more than one attribute value


Thanks again for your time
Reply