CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Feb 2009

    Arrow Pyxml generate Schema *HELP!!*

    Hi all, I don't know if this is in the right place but I am still rather green at XML stuff.

    I've been looking at xml and want to make a python program that can generate the xml schema instead of typing out the whole schema by hand. As far as I have seen, I need the pyxml program installed for the xml schema generation to work.

    I have made a simple xml doc based on the L4D2 game for trials:
    			<aid>Adrenaline shot</aid>
    			<Melee_Weapons>Frying Pan</Melee_Weapons>
    			<Volatile>Pipe Bombs</Volatile>
    			<Volatile>Boomer Bile</Volatile>
    				<Close_range>Auto Shotgun</Close_range>
    				<long_range>Sub-machine gun</long_range>
    				<long_range>Machine gun</long_range>
    Looking into other information I have made a very rough section of code to start with but I need a lot of help finishing it:

    from xml.SAX import make_parser
    from xml.SAX.handler import ContentHandler
    class l4d2Handler(ContentHandler):
         def __init__ (self,searchTerm):
         def startElement:
         def endElement:
    where I've put ////// i know there should be something more there, the code is made of pieces from tutorials I found that didn't explain enough to complete the program, and this is what I have made.

    I really need some help with this, and I need to complete it asap

  2. #2
    Join Date
    Feb 2009

    Re: Pyxml generate Schema *HELP!!*

    If anyone is actually looking at this, I have made some advancement with help from a friend

    from xml.sax import make_parser
    from xml.sax.handler import ContentHandler
    #import cgi
    class XmlDocHandler(ContentHandler):
        def __init__ (self):
            self.names = {}
            self.string = {}
            self.should_print = True
        def startDocument(self):
            print "Start of document stuff"
        def startElement(self, name, attrs):
            if not self.names.has_key(name):
                print "<xs:element name=\"" + name + "\">".strip()
                self.should_print = True
                self.should_print = False
    #            self.names[name] = None
    ##            if Game_content == 'characters':
    ##                self.humans = attrs.get('player_characters',"")
    ##                self.zombies = attrs.get('Infected',"")
    ##            elif items == 'items':
    ##                self.health = attrs.get('aid',"")
    ##                self.physical = attrs.get('Melee_Weapons',"")
    ##                self.throwable = attrs.get('Volatile',"")
    ##                self.Ranged_Weapons = attrs.get('Close_range',"")
    ##                self.Ranged_Weapons = attrs.get('long_range',"")
    ##                self.ammo_options = attrs.get('ammo',"")
    ##            return
        def characters(self, content):
    #        if not self.string.has_key(content):
            if self.should_print:
                print "<xs:pattern value=\"([a-z A-Z])*\"/>" + content +"\">".strip()
    #            print content.strip()
        def endElement(self, name):
            if not self.names.has_key(name):
                print "</xs:element name=\"" + name + "\">".strip()
                self.names[name] = None
    #FormData = cgi.FieldStorage()
    #searchTerm = FormData['humans'].value
    #searchTerm = FormData["zombies"].value
    #searchTerm = FormData["health"].value
    #searchTerm = FormData["physical"].value
    #searchTerm = FormData["throwable"].value
    #searchTerm = FormData["Ranged_Weapons"].value
    #searchTerm = FormData["ammo_options"].value
    parser = make_parser()
    curHandler = XmlDocHandler()
    While this does something useful it doesn't produce a good schema, What I need it to do is if all the "names" in an element are strings, to print
     <xs:pattern value=\"([a-z A-Z])*\"/>
    What it does at the moment is just print
     <xs:pattern value=\"([a-z A-Z])*\"/>
    everytime it sees a "name" which as you can imagine is a bit too often and rather untidy.

    Also any information on getting the information to align itself (tab) correctly would be very useful

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

By using this site, you agree to the Privacy Policy