Last active
December 21, 2015 18:39
-
-
Save magixsource/6348646 to your computer and use it in GitHub Desktop.
XML is first class citizen in scala Here is a xml named createedits_user,and i need @name and @cnname as format output like @name:@cnname
Plan A: copy @name and @cnname by myself (It's slowly,i don't like it)
Plan B: let program help me do it.got @name and @cnname and format output them. I choose plan B,so what program language use?
A: Java
B: S…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="gb2312"?> | |
<FormItems systemId="20049370122864" entryName="S_USER" tableName="用户" help="" isWorkFlow="" version=""> | |
<item name="sYS_RESERVER1" cnname="登录名" inputType="text" dataType="string" dbType="string" maxLength="6" constrain="must" editable="false" wheneditable="load"> | |
<value /> | |
</item> | |
<item name="sYS_RESERVER2" cnname="确认密码" inputType="password" dataType="string" dbType="string" maxLength="30" constrain="must"> | |
<value /> | |
</item> | |
<item name="sYS_RESERVER3" cnname="所在部门中文名称" inputType="hidden" dataType="string" dbType="string" maxLength="30" editable="false"> | |
<value /> | |
</FormItems> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.xml._ | |
import scala.collection.Map | |
object XmlReader{ | |
def main(args: Array[String]): Unit = { | |
val xmlFile = XML.load("CreateEditS_User.xml") | |
val itemNodes = xmlFile \\ "item" | |
val names = (itemNodes \\ "@name").toList | |
val cnnames = (itemNodes \\ "@cnname").toList | |
val zipped = names zip cnnames | |
zipped.foreach(println) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment