Print inside tag XML

Regex, python

1. interface .bat (double click), e.g., execute.bat

main.py drill4Opseq.xml tag1 tag2 > hasil.txt

2. python script, e.g., main.py

# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import re

def printData(beg, en, line):    
    reg = beg + r"(.*?)" + en
        
    "remove whitespace @beg.of line, esp. for title"
    line = re.sub(r"^\s+", "", line)

    if re.search(reg, line):    
        "print substring between beg and end"
        for match in re.finditer(reg, line, re.S):
            print(match.group(1), end="")
            print("\t", end="")
        print("")

def main():
    i = 0
    arg = 0
    insideTag = False
    #app = QtGui.QApplication(sys.argv)
    if len(sys.argv)")
                printData("\s", "=", line)
            printData("\"", "\"",  line)
            i=i+1
    fh.close()    

if __name__ == "__main__":
    main()

ps: pakai   buat indent 😀

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s