469,275 Members | 1,575 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

Extracting more than one attribute value

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?
Oct 28 '09 #1

✓ answered 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.

6 3192
Dormilich
8,651 Expert Mod 8TB
of course you can get more than one attribute at a time. the question is, if that is favourable for your application.
Oct 28 '09 #2
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.
Oct 28 '09 #3
Dormilich
8,651 Expert Mod 8TB
sorry, I canít help you with Linq (Iím not using .NET), only with the XPath.
Oct 28 '09 #4
Thanks Dormilich. What is the XPath approach to my problem?
Oct 28 '09 #5
Dormilich
8,651 Expert Mod 8TB
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.
Oct 28 '09 #6
Thanks again for your time
Oct 28 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Andrew Lord | last post: by
5 posts views Thread by Mateusz Loskot | last post: by
2 posts views Thread by David | last post: by
5 posts views Thread by Oleg.Ogurok | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.