dom4j

public void  getResult(String xmlString)
			throws UspMonitorException
	{
		String temp = xmlString.replace("xmlns", "xmlnss");
		StringReader stringReader = new StringReader(temp);
		SAXReader saxReader = new SAXReader();

		VolumeSnapshotResult volumeSnapshotResult = null;
		try
		{
			Document document = saxReader.read(stringReader);
			Element rootElement = document.getRootElement();
			List<Node> nodes = rootElement.selectNodes("./*");
                        //List<Node> nodes = rootElement.selectNodes("Root/Item/*");
			for (Node node : nodes)
			{
				volumeSnapshotResult = new VolumeSnapshotResult();
				String tmpTxt = node.getText();
				String tmpName = node.getName();
				if ("snapshotId".equals(tmpName))
				{
					volumeSnapshotResult.setSnapshotID(tmpTxt);
				}
				else if ("volumeId".equals(tmpName))
				{
					volumeSnapshotResult.setVolumeID(tmpTxt);
				}
                         }
                   }
                catch (DocumentException e)
		{
			e.printStackTrace();
		}
      }

你可能感兴趣的:(dom4j)