Reading/Writting to an XML File

satmisha
satmisha used Ask the Experts™
on
Hi Expert,

1. Need to Read & Write to an XML

2. Need to change Values from the following tags:
   <MsgNm>MaintainGNAApplicationDetailRequest</MsgNm>
   <MsgFormatCd>XML</MsgFormatCd>
   <MsgMajVersionNbr>2</MsgMajVersionNbr>
   <MsgMinVersionNbr>1</MsgMinVersionNbr>

Open in new window

3. Need to Change Following Tag value from 'String' value to 'Jim':
<Response>
   <Status>
    <RespCd>String</RespCd>
    <RespDesc>String</RespDesc>
    <ExplCd>String</ExplCd>
    <ExplDesc>String</ExplDesc>
   </Status>
   <CICAOutputData/>
  </Response>

Open in new window

==========

Enclosing complete XML:
<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSpy v2008 rel. 2 sp2 (http://www.altova.com)-->
<Envelope envelopeId="EMI" majorVersion="1" minorVersion="4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Z:\FRAUDD~2\260412\MAINTA~1.XSD">
 <Header>
  <TransactionBlk actor="Next" mustUnderstand="1" name="StdTransBlk" majorVersion="1" minorVersion="2">
   
   <MsgNm>MaintainGNAApplicationDetailRequest</MsgNm>
   <MsgFormatCd>XML</MsgFormatCd>
   <MsgMajVersionNbr>2</MsgMajVersionNbr>
   <MsgMinVersionNbr>1</MsgMinVersionNbr>
   
  </TransactionBlk>
  <SecurityBlk name="StdSecurityBlk" majorVersion="1" minorVersion="1" actor="Next" mustUnderstand="1">
   <SAMLBlk>
    <Assertion MajorVersion="1" MinorVersion="0" AssertionID="" Issuer="urn:aexp.com:applName" IssueInstant="2008-02-22T09:30:47.0Z">
     <AttributeStatement>
      <Subject>
       <NameIdentifier NameQualifier="urn:aexp.com:security" Format="urn:aexp.com:security:racf"/>
      </Subject>
      <Attribute AttributeName="" AttributeNamespace="">
       <AttributeValue/>
      </Attribute>
     </AttributeStatement>
    </Assertion>
   </SAMLBlk>
  </SecurityBlk>
 </Header>
 <Body>
  <Request>
   <BasicGrp>
    <PCNGrp>
     <PCNIssueDt>04\2011</PCNIssueDt>
     
    </PCNGrp>
    <SuppGrp>
     <SuppNbr>123</SuppNbr>
     <PersonelInfoGrp>
      
      <CustBirthDt>1976/02/28</CustBirthDt>
     </PersonelInfoGrp>
     <CustinfoGrp>
      
      <Billind>Y</Billind>
     </CustinfoGrp>
     <CompanyInfoGrp>
      <CompanyNm>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</CompanyNm>
     </CompanyInfoGrp>
     <EmploymentInfoGrp>
      <EmployerNm>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</EmployerNm>
     </EmploymentInfoGrp>
     <AddrInfoGrp>
      <AddrTypeCd>AA</AddrTypeCd>
      
      <IPAddr>123456789012345</IPAddr>
     </AddrInfoGrp>
     <AddrInfoGrp>
      <AddrTypeCd>AA</AddrTypeCd>
      
      <IPAddr>123456789012345</IPAddr>
     </AddrInfoGrp>
     <AppDecGrp>
      
      <FinalDecRsnCd5>XX</FinalDecRsnCd5>
     </AppDecGrp>
     <PhoneGrp>
      
      <ExtnNbr>1234567</ExtnNbr>
     </PhoneGrp>
     <PhoneGrp>
      
      <ExtnNbr>1234567</ExtnNbr>
     </PhoneGrp>
     <CIPGrp>
      <TaxID>123456789012345678</TaxID>
     </CIPGrp>
     <BalTrfrGrp>
      
      <BalTrfrAcct4>12345678901234567890</BalTrfrAcct4>
     </BalTrfrGrp>
    </SuppGrp>
    <SuppGrp>
     <SuppNbr>123</SuppNbr>
     <PersonelInfoGrp>
      <SfxNm>XXXXXXXXXXXXXXXXXXXX</SfxNm>
      <LstNm>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</LstNm>
      <FirstNm>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</FirstNm>
      <MidNm>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</MidNm>
      <CustBirthDt>1976/02/28</CustBirthDt>
     </PersonelInfoGrp>
     <CustinfoGrp>
      <CustIdTypeCd>ABCDEFG</CustIdTypeCd>
      <CustId>ABCDEFGHIJKLMNOPQR</CustId>
      <AffiliateId>ABCDEFGHIJK</AffiliateId>
      <AcctNum>1234567890123456789</AcctNum>
      <Billind>Y</Billind>
     </CustinfoGrp>
     <CompanyInfoGrp>
      <CompanyNm>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</CompanyNm>
     </CompanyInfoGrp>
     <EmploymentInfoGrp>
      <EmployerNm>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</EmployerNm>
     </EmploymentInfoGrp>
     <AddrInfoGrp>
      <AddrTypeCd>AA</AddrTypeCd>
      <AddrStrLine1>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AddrStrLine1>
      <AddrStrLine2>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AddrStrLine2>
      <AddrStrLine3>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AddrStrLine3>
      <AddrStrLine4>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AddrStrLine4>
      <CityNm>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</CityNm>
      <CntryRegnCd>APA</CntryRegnCd>
      <CntryCd>IND</CntryCd>
      <ZipCd>XXXXXXXXXXXXXXX</ZipCd>
      <EmailAddrTxt>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX@axp.com</EmailAddrTxt>
      <IPAddr>123456789012345</IPAddr>
     </AddrInfoGrp>
     <AddrInfoGrp>
      <AddrTypeCd>AA</AddrTypeCd>
      <AddrStrLine1>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AddrStrLine1>
      <AddrStrLine2>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AddrStrLine2>
      <AddrStrLine3>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AddrStrLine3>
      <AddrStrLine4>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AddrStrLine4>
      <CityNm>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</CityNm>
      <CntryRegnCd>APA</CntryRegnCd>
      <CntryCd>IND</CntryCd>
      <ZipCd>XXXXXXXXXXXXXXX</ZipCd>
      <EmailAddrTxt>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX@axp.com</EmailAddrTxt>
      <IPAddr>123456789012345</IPAddr>
     </AddrInfoGrp>
     <AppDecGrp>
      <AppStatus>A</AppStatus>
      <FinalDecRsnCd1>XX</FinalDecRsnCd1>
      <FinalDecRsnCd2>XX</FinalDecRsnCd2>
      <FinalDecRsnCd3>XX</FinalDecRsnCd3>
      <FinalDecRsnCd4>XX</FinalDecRsnCd4>
      <FinalDecRsnCd5>XX</FinalDecRsnCd5>
     </AppDecGrp>
     <PhoneGrp>
      <TypeCd>A</TypeCd>
      <TypeSeqno>123</TypeSeqno>
      <ContctCd>1</ContctCd>
      <CntryNbr>123</CntryNbr>
      <LineNbr>123456789012345</LineNbr>
      <ExtnNbr>1234567</ExtnNbr>
     </PhoneGrp>
     <PhoneGrp>
      <TypeCd>A</TypeCd>
      <TypeSeqno>123</TypeSeqno>
      <ContctCd>1</ContctCd>
      <CntryNbr>123</CntryNbr>
      <LineNbr>123456789012345</LineNbr>
      <ExtnNbr>1234567</ExtnNbr>
     </PhoneGrp>
     <CIPGrp>
      <TaxID>123456789012345678</TaxID>
     </CIPGrp>
     <BalTrfrGrp>
      <BalTrfrAcct1>12345678901234567890</BalTrfrAcct1>
      <BalTrfrAcct2>12345678901234567890</BalTrfrAcct2>
      <BalTrfrAcct3>12345678901234567890</BalTrfrAcct3>
      <BalTrfrAcct4>12345678901234567890</BalTrfrAcct4>
     </BalTrfrGrp>
    </SuppGrp>
   </BasicGrp>
  </Request>
  <Response>
   <Status>
    <RespCd>String</RespCd>
    <RespDesc>String</RespDesc>
    <ExplCd>String</ExplCd>
    <ExplDesc>String</ExplDesc>
   </Status>
   <CICAOutputData/>
  </Response>
 </Body>
</Envelope>

Open in new window


Please Help..................................!!!!!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Pls Help Experts
ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
Can you use LINQ?

Author

Commented:
currently I am using vs 2008, So I can use LINQ as well.... Looking forward to hearing from you.
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
See if this helps:

Imports System.Xml.Linq

Module Module1

    Sub Main()
        Dim xdoc As XDocument = XDocument.Load("input.xml")

        '''''''''''''''''''''''''''''''''''''''''''''''
        ' Change TransactionBlk children
        '''''''''''''''''''''''''''''''''''''''''''''''
        For Each TransactionBlk In xdoc.Descendants("TransactionBlk")
            Dim MsgNm = TransactionBlk.Element("MsgNm")
            Dim MsgFormatCd = TransactionBlk.Element("MsgFormatCd")
            Dim MsgMajVersionNbr = TransactionBlk.Element("MsgMajVersionNbr")
            Dim MsgMinVersionNbr = TransactionBlk.Element("MsgMinVersionNbr")

            If MsgNm IsNot Nothing Then MsgNm.Value = "new value"
            If MsgFormatCd IsNot Nothing Then MsgFormatCd.Value = "new value"
            If MsgMajVersionNbr IsNot Nothing Then MsgMajVersionNbr.Value = "new value"
            If MsgMinVersionNbr IsNot Nothing Then MsgMinVersionNbr.Value = "new value"
        Next


        '''''''''''''''''''''''''''''''''''''''''''''''
        ' Change Response/Status children
        '''''''''''''''''''''''''''''''''''''''''''''''
        For Each Response In xdoc.Descendants("Response")
            For Each Status In Response.Elements("Status")
                Dim RespCd = Status.Element("RespCd")
                Dim RespDesc = Status.Element("RespDesc")
                Dim ExplCd = Status.Element("ExplCd")
                Dim ExplDesc = Status.Element("ExplDesc")

                If RespCd IsNot Nothing AndAlso RespCd.Value = "String" Then RespCd.Value = "Jim"
                If RespDesc IsNot Nothing AndAlso RespDesc.Value = "String" Then RespDesc.Value = "Jim"
                If ExplCd IsNot Nothing AndAlso ExplCd.Value = "String" Then ExplCd.Value = "Jim"
                If ExplDesc IsNot Nothing AndAlso ExplDesc.Value = "String" Then ExplDesc.Value = "Jim"
            Next
        Next

        xdoc.Save("output.xml")
    End Sub

End Module

Open in new window

Author

Commented:
Thankx Expert, Apologies for late response..!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial