MIRC socket script - XML Root

By ipewannasay on Aug 08, 2010

hi guys :wink:

i need your help for my mirc script
i try to create some xml parser for mirc HTTP socket script

you can find the xml file sample here

http://api.erepublik.com/v2/feeds/citizen_by_name/xml/ipewannasay

there are so many tag named

  1. at citizen/name
  2. at citizen/residence/region/name
  3. at citizen/residence/country/name
  4. at citizen/employer/name
  5. at citizen/skills/skill/name
  6. at citizen/party/name
  7. at citizen/citizenship/region/name
  8. at citizen/citizenship/country/name

I had a problem to access the tag that has text: [b]Allies of Indonesia
[/b]

then i have made a script that made a temporary root address

can you help me simplify that code :D
or maybe you have some other method to parse xml in mirc language please share here

on *:text:.link*:#: {
  if ( $me != %botnick ) halt
  else {
    var %idtlp $right($ticks,8)
    var %sntlp socktlp. [ $+ [ %idtlp ] ]
    set %chan. [ $+ [ %sntlp ] ] $chan
    set %nick. [ $+ [ %sntlp ] ] $nick
    if ( $2 == $null ) syntax $1 %chan. [ $+ [ %sntlp ] ]
    elseif ( $2 != $null ) {
      sockclose %sntlp
      var %lc. [ $+ [ %sntlp ] ] $replace( $2- ,$chr(32), $chr(37) $+ 20 )
      set %ln. [ $+ [ %sntlp ] ] $( $+ /v2/feeds/citizen_by_name/xml/ $+ %lc. [ $+ [ %sntlp ] ] )
      notice %nick. [ $+ [ %sntlp ] ] Processing Request...
      sockopen %sntlp api.erepublik.com 80
    }
    else syntax $1 %chan. [ $+ [ %sntlp ] ]
  }
}

on *:SOCKOPEN:socktlp*: {
  sockwrite -nt $sockname GET %ln. [ $+ [ $sockname ] ] HTTP/1.1
  unset %ln. [ $+ [ $sockname ] ]
  sockwrite -nt $sockname Host: api.erepublik.com
  sockwrite -nt $sockname $crlf
}

on *:SOCKREAD:socktlp*: {
  var %sntlp $sockname
  if ($sockerr) {
    msg %chan. [ $+ [ %sntlp ] ] Socket Error: %sntlp $+ . Error code: $sockerr Please inform $me of this error message.
    unset %chan. [ $+ [ %sntlp ] ] %nick. [ $+ [ %sntlp ] ]
    sockclose %sntlp
  }
  else {
    set %rd. [ $+ [ %sntlp ] ]
    var %rdv %rd. [ $+ [ %sntlp ] ]
    sockread %rdv
    if ( $nohtml( %rdv ) == $null ) {
      if ( <citizen> isin %rdv ) set %i. [ $+ [ %sntlp ] ] 0
      if ( / !isin %rdv ) {
        inc %i. [ $+ [ %sntlp ] ]
        var %ii %i. [ $+ [ %sntlp ] ]
        set %th [ $+ [ %ii ] $+ . $+ [ %sntlp ] ] %rdv
      }
      var %iii 0
      while ( %iii <= %i. [ $+ [ %sntlp ] ] ) {
        inc %iii
        set %echothread %echothread %th [ $+ [ %iii ] $+ . $+ [ %sntlp ] ]
      }
      if ( %echothread != $null ) echo 4 -a %echothread
      unset %echothread
    }

    elseif ( $nohtml( %rdv ) != $null ) {
      echo 3 -a %i. [ $+ [ %sntlp ] ] %rdv
      if ( <message> isin %rdv ) {
        set %error. [ $+ [ %sntlp ] ] $nohtml( %rdv )
        msg %chan. [ $+ [ %sntlp ] ] ERROR: %error. [ $+ [ %sntlp ] ]
        unset %chan. [ $+ [ %sntlp ] ] %nick. [ $+ [ %sntlp ] ] %rd. [ $+ [ %sntlp ] ] %error. [ $+ [ %sntlp ] ] %i. [ $+ [ %sntlp ] ]
        sockclose %sntlp
        halt
      }
    }
    if ( $nohtml( %rdv ) == $null ) {
      if ( / isin %rdv ) {
        if ( ></ !isin %rdv ) {
          if ( </ isin %rdv ) {
            var %ii %i. [ $+ [ %sntlp ] ]
            unset %th [ $+ [ %ii ] $+ . $+ [ %sntlp ] ]
            dec %i. [ $+ [ %sntlp ] ]
          }
          elseif ( /> isin %rdv ) echo 4 -a EMPTY THREAD %rdv
        }
        else echo 4 -a EMPTY THREAD %rdv
      }
      if ( </citizen> isin %rdv ) {
        echo 4 -a DOR :|
        unset %username. [ $+ [ %sntlp ] ] %profile. [ $+ [ %sntlp ] ] %donate. [ $+ [ %sntlp ] ]
        unset %chan. [ $+ [ %sntlp ] ] %nick. [ $+ [ %sntlp ] ] %i. [ $+ [ %sntlp ] ] %rd. [ $+ [ %sntlp ] ] %th1. [ $+ [ %sntlp ] ] %th2. [ $+ [ %sntlp ] ] %th3. [ $+ [ %sntlp ] ] %th4. [ $+ [ %sntlp ] ]
        sockclose $sockname
      }
    }
  }
}

Comments

Sign in to comment.
ipewannasay   -  Aug 09, 2010

i couldn't post it in forum :s

 Respond  
Jethro   -  Aug 08, 2010

napa, more precisely, you should direct ipewannasay to mIRC Scripting forum. He's expecting a suggestion for his existing script to be simplified or given a better approach. :p

 Respond  
napa182   -  Aug 08, 2010

wrong place to ask for help. You should have posted this in the forum under mIRC Snippet Requests

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.