Advertisement
mbazs

Untitled

Aug 3rd, 2017
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. from lxml import etree
  2. import sys
  3. file = sys.argv[1]
  4. if not file:
  5.     print("usage: {} <XSD-or-WSDL-path>".format(sys.argv[0]))
  6.     exit()
  7.  
  8. def main():
  9.     print("input file: {}".format(file))
  10.     tree = etree.parse(file)
  11.     for el in tree.xpath("//*[local-name() = 'schema']"):
  12.         tnss = el.xpath("@targetNamespace")[0].split("/")[-2]
  13.         print("processing {} ...".format(tnss))
  14.         ofn = "{}.xsd".format(tnss)
  15.         with open(ofn, "wb") as of:
  16.             of.write(etree.tostring(el, encoding="utf-8", xml_declaration="1.0"))
  17.         print("file {} written successfully".format(ofn))
  18.  
  19. if __name__ == "__main__":
  20.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement