日期:2014-05-20 浏览次数:20982 次
public static List elementMap = new ArrayList(); public static void main(String[] args) { File file = new File("G:\\Workspace\\InterfaceGZRC\\doc\\TCO1.xml"); byte[] val = new byte[4690]; BufferedReader in; DataOutputStream out; try { InputStream input = new FileInputStream(file); input.read(val, 0, val.length); for (int i = 0; i < val.length; i++) { System.out.println((char)val[i]); } Socket socket = new Socket("localhost", 5008); in = new BufferedReader(new InputStreamReader(socket .getInputStream())); out = new DataOutputStream(socket.getOutputStream()); out.write(val); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public void getxml(InputStream in) { byte[] val = new byte[4690]; try { //InputStream in = new FileInputStream(file); InputStream inputStream=new DataInputStream(in); inputStream.read(val, 0, val.length); inputStream.close(); for (int i = 0; i < val.length; i++) { System.out.println((char)val[i]); } ByteArrayInputStream bais = new ByteArrayInputStream(val); SAXReader saxReader = new SAXReader(); Document document = saxReader.read(bais); Element rootElement = document.getRootElement(); new Xml_Parse().removePrefix(rootElement); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
private void removePrefix(Element element) { if (element.getData().toString().trim() != null && !element.getData().toString().trim().equals("")) { elementMap.add(0, ":" + element.getQName().getName() + ":" + element.getData().toString()); } if (element != null && element.getQName().getName().length() > 0) { element.setQName(new QName(element.getQName().getName())); Iterator elementIterator = element.elementIterator(); while (elementIterator.hasNext()) { this.removePrefix((Element) elementIterator.next()); } }