How can i generate a schema inferred from an xml document using xml.dom.minidom

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lostangel696
    New Member
    • Dec 2008
    • 4

    How can i generate a schema inferred from an xml document using xml.dom.minidom

    Could somoene please guide me on how i would go about generating a schema using minidom inferred from an xml document that i have made.
    Thankyou
  • lostangel696
    New Member
    • Dec 2008
    • 4

    #2
    please

    help. I basicly need to use minidom to extract the element names from an xml document and output them to another, to form a schema.

    Comment

    • lostangel696
      New Member
      • Dec 2008
      • 4

      #3
      bump

      bump please help me!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!

      Comment

      • lostangel696
        New Member
        • Dec 2008
        • 4

        #4
        I need to make an application to read an xml document, and extract the names between the tags and print them.
        I do not want duplicates
        so say

        <root>
        <weapon>P228
        <price>468
        </price>
        </weapon>
        <weapon>USP
        <price>500
        </price>
        </weapon>
        </root>

        if this is the xml file, then i want the application to print,
        <root>
        <weapon>
        <price>

        Thanks.

        Comment

        • bvdet
          Recognized Expert Specialist
          • Oct 2006
          • 2851

          #5
          Using xml.dom.minidom , you can extract tag data using method doc.getElements ByTagName() and reading attribute firstChid.data. Note that "root" has no data.

          [code=Python]from xml.dom import minidom

          def getTagData(doc, tag):
          output = []
          for elem in doc.getElements ByTagName(tag):
          data = str(elem.firstC hild.data).stri p()
          if data:
          output.append(d ata)
          return output

          doc = '''<root>
          <weapon>P228
          <price>468
          </price>
          </weapon>
          <weapon>USP
          <price>500
          </price>
          </weapon>
          </root>'''

          docXML = minidom.parseSt ring(doc)

          for tag in ('root', 'weapon', 'price'):
          data = getTagData(docX ML,tag)
          if data:
          for item in getTagData(docX ML,tag):
          print "Tag '%s': %s" % (tag, item)
          else:
          print "No data to display for tag '%s'" % tag[/code]
          Output:[code=Python]>>> No data to display for tag 'root'
          Tag 'weapon': P228
          Tag 'weapon': USP
          Tag 'price': 468
          Tag 'price': 500
          >>> [/code]

          Comment

          Working...