⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 groovyrcv.groovy

📁 开源的axis2框架的源码。用于开发WEBSERVER
💻 GROOVY
字号:
import java.io.*;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.xpath.XPathAPI;
import groovy.xml.*
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.*;
import org.xml.sax.*;

class GroovyRcv{

	public static void main(args){
        String value = "<ADDRESS><DET><NAME>Ponnampalam Thayaparan</NAME> <OCC>Student</OCC><ADD>3-2/1,Hudson Road,Colombo-03</ADD><GENDER>Male</GENDER></DET><DET><NAME>Eranka Samaraweera</NAME><OCC>Student</OCC><ADD>Martara</ADD><GENDER>Male</GENDER></DET><DET><NAME>Sriskantharaja Ahilan</NAME><OCC>Student</OCC><ADD>Trincomalee</ADD><GENDER>Male</GENDER></DET></ADDRESS>"
		println new GroovyRcv().echo(new StringReader(value))
    }

	Object echo(StringReader arg){

	 List addNodeValues = []
	 List nameNodeValues = []
	 int countEmp = -1

	 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance()
	 DocumentBuilder builder = factory.newDocumentBuilder()
	 Document doc = builder.parse(new InputSource(arg))

	 NodeList detNodes = XPathAPI.selectNodeList(doc,"ADDRESS/DET")
	 for(detNodeIndex in 0..(detNodes.getLength()-1)) {
		 NodeList nameNodes = XPathAPI.selectNodeList(detNodes.item(detNodeIndex),"NAME")
	
		 for(nameNodeIndex in 0..(nameNodes.getLength()-1)) {
			 Node nameNodeValue = nameNodes.item( nameNodeIndex ).getFirstChild()
			 nameNodeValues += [nameNodeValue]
		 }
	
		 NodeList addNodes = XPathAPI.selectNodeList(detNodes.item(detNodeIndex),"ADD")
		 for(addNodeIndex in 0..(addNodes.getLength()-1)) {
			 Node addNodeValue = addNodes.item(addNodeIndex).getFirstChild()
			 addNodeValues += [addNodeValue]
		 }
		 countEmp++
	 }//for

	StringWriter writer = new StringWriter()
    MarkupBuilder xmlBuilder = new MarkupBuilder(writer)
	xmlBuilder.person(){
	 	for(x in 0..countEmp){
			employee(){
			name(nameNodeValues[x])
			address(addNodeValues[x])
			tdate(new java.util.Date())
	 	}
	  }
	 }

   return writer
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -