Parsing Nested XML File Better Approach

satmisha
satmisha used Ask the Experts™
on
Hi Expert,

I am having big XML File, Need to do followings:

1. Reading Entire XML.
2. Validate followings in XML:
    # WellFormed XML
    # CorrectDate Format.
    # Field Values Etc.
3. Need to change the Value of few Tags.
4. Insert the Data inside DataBase

Since there various Ways to do this, What would be the best approach. Looking forward to hearing from you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Rose BabuSenior Team Manager

Commented:
can you post the XML file and the tags details to be updated?

Author

Commented:
Thanks for  your reply..Here is the file....

<?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~2.XSD">
  <Header>
    <TransactionBlk actor="Next" mustUnderstand="1" name="StdTransBlk" majorVersion="1" minorVersion="2">

      <MsgNm>MaintainGNAFraudDetailRequest</MsgNm>
      <MsgFormatCd>XML</MsgFormatCd>
      <MsgMajVersionNbr>2</MsgMajVersionNbr>

    </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>
      <RequestorId>IDN</RequestorId>
      <OpCd>A</OpCd>
      <MktCd>APA</MktCd>
      <FRDCaseGrp>
        <CaseNbr>A1234567890</CaseNbr>
        <CaseRelCnt>2</CaseRelCnt>
        <LstAssgnRelNbr>1234</LstAssgnRelNbr>
        <DelAllRel>N</DelAllRel>
        <RelGrp>
          <RelNbr>1234</RelNbr>
          <FRDRelGrp>
            <PositiveMatchCnt>01</PositiveMatchCnt>

            <CBORskInd1>X</CBORskInd1>

          </FRDRelGrp>
          <FRDRelGrp>
            <PositiveMatchCnt>02</PositiveMatchCnt>

            <CBORskInd1>X</CBORskInd1>

          </FRDRelGrp>
          <NoteGrp>
            <NoteSeqNbr>01</NoteSeqNbr>

          </NoteGrp>
          <NoteGrp>
            <NoteSeqNbr>02</NoteSeqNbr>

          </NoteGrp>
          <AddrGrp>

            <AddrRskFlagInd>Y</AddrRskFlagInd>

          </AddrGrp>
          <AddrGrp>

            <AddrRskFlagInd>Y</AddrRskFlagInd>

          </AddrGrp>
          <PhoneGrp>

            <PhoneRskFlagInd>Y</PhoneRskFlagInd>
          </PhoneGrp>
          <PhoneGrp>

            <PhoneRskFlagInd>Y</PhoneRskFlagInd>
          </PhoneGrp>
          <VarGrp>

            <RelVarRskFlag>X</RelVarRskFlag>

          </VarGrp>
        </RelGrp>
        <RelGrp>
          <RelNbr>1234</RelNbr>
          <FRDRelGrp>

            <LstUpdtDt>02/04/2012</LstUpdtDt>

          </FRDRelGrp>
          <FRDRelGrp>
            <PositiveMatchCnt>02</PositiveMatchCnt>

            <SENbr>1234567890</SENbr>
          </FRDRelGrp>
          <NoteGrp>
            <NoteSeqNbr>01</NoteSeqNbr>
            <NoteDesc>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</NoteDesc>
          </NoteGrp>
          <NoteGrp>
            <NoteSeqNbr>02</NoteSeqNbr>
            <NoteDesc>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</NoteDesc>
          </NoteGrp>
          <AddrGrp>
            <AddrTypeCd>S </AddrTypeCd>

            <AddrLocatorCd>XXXXXXXXXXXXXXXXXXXXXXX</AddrLocatorCd>
          </AddrGrp>
          <AddrGrp>
            <AddrTypeCd>S </AddrTypeCd>
          </AddrGrp>
          <PhoneGrp>

            <PhoneRskFlagInd>Y</PhoneRskFlagInd>
          </PhoneGrp>
          <PhoneGrp>

            <PhoneRskFlagInd>Y</PhoneRskFlagInd>
          </PhoneGrp>
          <VarGrp>

            <VarVal>XXXX</VarVal>
          </VarGrp>
        </RelGrp>
      </FRDCaseGrp>
    </Request>
  </Body>
</Envelope>

Author

Commented:
Want to update following Tags with new Values:

  <MsgNm>MaintainGNAFraudDetailRequest</MsgNm>
      <MsgFormatCd>XML</MsgFormatCd>
      <MsgMajVersionNbr>2</MsgMajVersionNbr>


Pls Suggest.

Looking forward to hearing from you.
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Author

Commented:
Increasing the Points to 500.. Pls Help....
1. Reading Entire XML.
2. Validate followings in XML:
    # WellFormed XML
    # CorrectDate Format.
    # Field Values Etc.
3. Need to change the Value of few Tags.
4. Insert the Data inside DataBase

I would suggest

Read the XML File in the XMLDocument. If you get an exception while loading the xml in the XMLDocument object then file is not well formed.

Once XML is Successfully load then Validate it using XSD for Data validation.
Refer below link for code.
http://social.msdn.microsoft.com/forums/en-US/xmlandnetfx/thread/88eb8ff3-bfc3-473d-a778-e489a4776b10/
Using XSD you can check the data and missing tags as well.

Using Xmldocument you can write/ change data on some nodes and then you can update the same in database.

Author

Commented:
Thnanx 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