Extracting more than one attribute value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pisicuta
    New Member
    • Oct 2009
    • 8

    Extracting more than one attribute value

    I have an XML file that looks something like this
    Code:
    <MyXML>
    	<Stuff IDX="1"  Name="Swish" Manufacturer="Grimoto" ParentRef = "0" Ref = "1234567" />
    	: More elements
    	: More elements
    		<Stuff IDX="0"  Name="Swosh" Manufacturer="Grimoto" ParentRef = 1234567" Ref = "9876543" />
    		: More elements
    		: More elements
    		</IDX>
    	</IDX>
    <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?
    Last edited by Dormilich; Oct 28 '09, 11:33 AM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    of course you can get more than one attribute at a time. the question is, if that is favourable for your application.

    Comment

    • pisicuta
      New Member
      • Oct 2009
      • 8

      #3
      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.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        sorry, I can’t help you with Linq (I’m not using .NET), only with the XPath.

        Comment

        • pisicuta
          New Member
          • Oct 2009
          • 8

          #5
          Thanks Dormilich. What is the XPath approach to my problem?

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

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

            nevertheless, it should be something like
            Code:
            @name or @ref
            @*[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.

            Comment

            • pisicuta
              New Member
              • Oct 2009
              • 8

              #7
              Thanks again for your time

              Comment

              Working...