ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

regarding %scan and %subst

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • regarding %scan and %subst

    Hi all

    i have string length of 1000 A

    that is XML tags.

    like this


    here i have to fetch the data like this
    i have to skip the tag and fetch the next tag. that is how to read second tag.

    very urgent

    thanx in advance

    mag

  • #2
    Re: regarding %scan and %subst

    For XML there will ALWAYS be a less than and greater than sign for each element.
    you need to be in a do loop the scans for the less than then the greater than signs then make the next scan start (at bottom of do loop) to equal position og greater than sign + 1



    this should get you started

    jamie
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: regarding %scan and %subst

      Hi Jamie

      Thanx

      i am doing like that but my problem is that is i have to skip first 3 TAG these are bellow

      after that
      123456789SLAC .......

      with this field i have to insert

      NAME VALUE
      policy_number 123456789

      then i have to skip the means i don't want to insert into PF.

      this is my requirement.

      thanx in advance

      magesh

      Comment


      • #4
        Re: regarding %scan and %subst

        I assume that ur XmlString is 1000A and will contain data like this
        123456789SLAC .......

        U can write some sort of code like this....

        Xmlstring 1000A;
        index = 1;
        Position = 1;
        length = %len(%trim(Xmlstring));

        Do 3 ;
        Position = %Scan('>':%Trim(XmlString):Position) ;
        Enddo;

        index = position + 1;

        Dow ( index <= length )
        If (%Subst(%trim(XmlString):index:1) = '<')

        If ( (%Subst(%trim(XmlString):index+1:1) = '/' )
        NxtSymbol = %Scan('>':%Trim(XmlString):index) ;
        index = NxtSymbol+1;
        iter ;
        Endif;

        Nextgtsyml = %Scan('>':%Trim(XmlString):index) ;
        CaptureData = Capture data + %Subst( (%trim(XmlString):index+1:Nextgtsyml-1 );
        index = Nextgtsyml + 1;
        else
        Pos = %Scan('<':%Trim(XmlString):index) ;
        CaptureData = Capture data + %Subst( (%trim(XmlString):index+1os-1 );
        index = pos + 1;
        Endif;
        Enddo ;

        Finally Capture data will hold the data u want.
        It can be string or can be an array depending on ur convienence.
        Thanks,
        Giri

        Comment


        • #5
          Re: regarding %scan and %subst

          Doctor doctor - it hurts when I bang my head into this brick wall.

          Then stop doing it my son - parsing XML in RPG is not for the faint of heart (maybe for the feeble of mind but ...)

          Stop trying to re-invent the wheel. There are many people who have interfaced Java XML parsers to RPG. There are even more who have used Scott Klement's port of Expat (www.scottklement.com) to parse XML. IN V5R4 RPG has built in XML parsing.

          In trying to do it yourself unless you are guaranteed it is a one-time-no-changes job you are building up a world of hurt for yourself.

          Use an existing tool - stop beating your head into the wall.

          Comment

          Working...
          X