Skip to content

Instantly share code, notes, and snippets.

@benwaffle
Last active August 29, 2015 14:11
Show Gist options
  • Save benwaffle/ac73e649ee945656ae0a to your computer and use it in GitHub Desktop.
Save benwaffle/ac73e649ee945656ae0a to your computer and use it in GitHub Desktop.
complex wsdl types to scala
import scala.xml.XML
object Main extends App {
def getType(w: String) = w dropWhile ( _ != ':' ) drop(1) capitalize
val xml = XML.loadFile("Sample.wsdl")
val types = (xml \ "types" \ "schema" \ "complexType")
types map { complextype =>
println("case class %s(".format(complextype.attribute("name").get))
println((complextype \ "sequence" \ "element") map { elem =>
" val %s: %s = None".
format (elem.attribute("name").get,
getType(elem.attribute("type").getOrElse("xs:any").toString))
} mkString ",\n")
println(" )")
}
}
case class login(
val username: String = None,
val password: String = None,
val userType: Int = None
)
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions>
<wsdl:types>
<xs:schema>
<xs:complexType name="login">
<xs:sequence>
<xs:element minOccurs="0" name="username" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="password" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="userType" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
</wsdl:definitions>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment