How to parse XML based on tag fields

LordSM

New member
Joined
Jun 25, 2007
Messages
1
Programming Experience
Beginner
If I have the following XML File

HTML:
<AccountRequest StaffID="1234">
    <KeyValue>1367932986</KeyValue>
    <RequestorName>sam1</RequestorName>
    <LoginName>Sam</LoginName>
    <Extension>Sam</Extension>
    <MailStop>Sam</MailStop>
    <Date>Sam</Date>
    <JobTitleTextBox>Sam</JobTitleTextBox>
    <EmploymentType>
    </EmploymentType>
    <DeptNo>Sam</DeptNo>
    <Site>
      <Site>USBO</Site>
    </Site>
    <Level2>
      <Level2>Provision Installer</Level2>
      <Level2>Software Installer</Level2>
    </Level2>
    <Level3>
      <Level3>Provision Administrator</Level3>
    </Level3>
    <Level4 />
    <Other>King</Other>
    <RequiredSection>
    </RequiredSection>
    <Supervisor>
    </Supervisor>
    <SupervisorExtention>
    </SupervisorExtention>
    <SupervisorEmail>sjoo</SupervisorEmail>
  </AccountRequest>
  <AccountRequest StaffID="1234">
    <KeyValue>1543904352</KeyValue>
    <RequestorName>Sam2</RequestorName>
    <LoginName>Sam</LoginName>
    <Extension>Sam</Extension>
    <MailStop>Sam</MailStop>
    <Date>Sam</Date>
    <JobTitleTextBox>Sam</JobTitleTextBox>
    <EmploymentType>Lord DBA</EmploymentType>
    <DeptNo>Sam</DeptNo>
    <Site>
      <Site>USBO</Site>
      <Site>USWA</Site>
    </Site>
    <Level1>Report Viewer</Level1>
    <Level3>
      <Level3>Report Administrator</Level3>
      <Level3>Provision Administrator</Level3>
    </Level3>
    <Level4>
      <Level4>OPSWARE Security Administrator</Level4>
      <Level4>OPSWARE Implementer</Level4>
    </Level4>
    <Other>
    </Other>
    <ProvisionAdministratorAccess>
      <ProvisionAdministratorAccess>Linux</ProvisionAdministratorAccess>
      <ProvisionAdministratorAccess>Windows</ProvisionAdministratorAccess>
    </ProvisionAdministratorAccess>
    <RequiredSection>New Chap</RequiredSection>
    <Supervisor>Kim</Supervisor>
    <SupervisorExtention>1234</SupervisorExtention>
    <SupervisorEmail>sjoo</SupervisorEmail>
  </AccountRequest>
I need to get values for only those tags which have a matching staff Id and key value... like only account tags which have matching values should be parsed and there values be stored... Kindly help.. I am really stuck now. I am trying to do something like save all values of ProvisionAdministrarorAccess and level2 and similar tags, once staff id and key value have matched..
 
Last edited by a moderator:
There is a lot of functionality for this in the System.XML namespace. This provides a plethora of objects to modify, create, write, read, etc.

For you purpose you may want to look at the XmlTextReader. All you have to do is pass it a stream and you should be able to navigate to the parts of the xml you want to capture.
 
dim reader as new xmlTextReader(xml file)

while reader.read
reader.readtoelement("AccountRequest")
if reader.value = REQUIREMENT
PERFORM FUNCTION (AND READ THE REMAINING INFO REQUIRED)
End if
End While
 
LordSM, is your profile correct that you have to use .NET 2.0? If you were able to use .NET3.5 I will post you details of how to perform this function using LINQ, which will be a very, very elegant solution.
 
Back
Top