Results 1 to 1 of 1

Thread: Request assistance in extracting data from XML document

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2022
    Location
    West Sussex
    Posts
    29

    Request assistance in extracting data from XML document

    Hi All,

    Hope someone can help.

    I have an XML doc which reads:

    Code:
    <?xml version="1.0" encoding="ISO-8859-1" ?>		
    		
    <TacRef>		
    	<TacRefData Num="0">	
    		<MainData>
    			<CategoryId>8200</CategoryId>
    			<SubCategoryId>8230</SubCategoryId>
    			<ClassTable>1432</ClassTable>
    		</MainData>
    	</TacRefData>
    	<TacRefData Num="1">	
    		<MainData>
    			<CategoryId>8400</CategoryId>
    			<SubCategoryId>8410</SubCategoryId>
    			<ClassTable>832</ClassTable>
    		</MainData>
    	</TacRefData>
    	<TacRefData Num="2">	
    		<MainData>
    			<CategoryId>8800</CategoryId>
    			<SubCategoryId>8610</SubCategoryId>
    			<ClassTable>22382</ClassTable>
    		</MainData>
    	</TacRefData>
    ...
    </TacRef>
    from which I am trying to extract data using the following code:

    Code:
    Dim myReader As XDocument = XDocument.Load("TacRefDB.xml")
    
    For Each TacRefData In myReader.Root.Descendants("TacRefData")
    
        TacRefDataNbr = TacRefData.Attribute("Num").Value
        CategoryID = TacRefData.Descendants("MainData").Elements("CategoryID").Value
        SubCategoryID = TacRefData.Descendants("MainData").Elements("SubCategoryID").Value
        ClassTable = TacRefData.Descendants("MainData").Elements("ClassTable").Value
    Next
    Once I have the variables read in I would store them in a collection of some description.

    The issue I have is I can read the individual TacRefData.Attribute("Num").Value - this will return 0, 1, 2, 3, 4... etc. but for my CategoryID, SubCategoryID and ClassTable everything is returned as Nothing.

    If anyone could point out what I'm doing wrong it would be appreciated.

    Regards

    EDIT

    User error - I was looking for CategoryID instead of CategoryId. I'm an idiot...
    Last edited by MHutcheon; Jan 13th, 2026 at 01:39 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width