{"id":7,"date":"2012-08-08T11:47:15","date_gmt":"2012-08-08T11:47:15","guid":{"rendered":"https:\/\/code4reference.com\/?p=7"},"modified":"2012-08-08T11:47:15","modified_gmt":"2012-08-08T11:47:15","slug":"code4referencexml-parsing-gradle-script","status":"publish","type":"post","link":"https:\/\/code4reference.com\/?p=7","title":{"rendered":"Code4Referencexml parsing gradle script"},"content":{"rendered":"<p>Gradle is a great tool for build management. Recently I started using it in my projects. In one of the requirements I had to parse the xml file using gradle. I started looking for help from blog and gradle documents but I hardly found any. I started fiddling around and discovered that it is achievable with the help of xmlParser class.<br \/>\nI would like to share this information with others and here is the example code. The xmlexample.xml contains root element attributes and child elements and their attributes. This example covers reading of all the possible attributes\/properties and element\u2019s value.<\/p>\n<pre>\n\n\n    \n        \n        \n    \n     This is simple xml parser in gradle \n\n<\/pre>\n<p>and the build.gradle is as following<\/p>\n<pre>\ntask parseXml() {\n    def parsedProjectXml = (new XmlParser()).parse('xmlexample.xml')\n    println parsedProjectXml.@name\n    println parsedProjectXml.@version\n    println \"ModuleList name : \" + parsedProjectXml.modulelist[0].@name +\n            \", shortName : \" + parsedProjectXml.modulelist[0].@shortName\n    parsedProjectXml.modulelist.module.each{ module -&gt;\n      println \"Name : \" +  module.@name + \", version : \" + module.@version\n    }\n    println parsedProjectXml.description.text()\n}\n<\/pre>\n<p>for executing the gradle, run the follwoing command.<\/p>\n<pre>\n$ gradle parseXml\nproject Name : xmlGradleProject, version : 1.0\nModuleList name : ModulesNameList, shortName : mnl\nName : firstModule, version : 1.1\nName : SecondModule, version : 2.1\nThis is simple xml parser in gradle\n:parseXml UP-TO-DATE\n\nBUILD SUCCESSFUL\n\nTotal time: 4.125 secs\n<\/pre>\n<p>you can also download source code from <a href=\"http:\/\/github.com\/rakeshcusat\/Code4Reference\/tree\/master\/GradleExample\/xmlparsing\">github<\/a>. Hope this blog helped you in someway. Please feel free to leave your comments or suggestions about the above post or the website.<\/p>\n<p><a href=\"http:\/\/code4reference.com\/how-to-dos\/\">Other How to dos<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Gradle is a great tool for build management. Recently I started using it in my projects. In one of the requirements I had to parse the xml file using gradle. I started looking for help from blog and gradle documents but I hardly found any. I started fiddling around and discovered that it is achievable [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/posts\/7","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7"}],"version-history":[{"count":0,"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/posts\/7\/revisions"}],"wp:attachment":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}