关于xml带命名空间的解析问题

关于xml带命名空间的解析问题,前不久公司实现了用 java调用.net webservice接口.由于系统之间传输的是带命名空间xml文件,开始始终解析得不到节点信息,一直纳闷了很久,后来看了一为牛人的blog,终于实现了.
 
public List loadXml(String path)
{

Flights flight;
List list = new ArrayList();
String bunkList = "";
String takeOffCity = "";
String arriveCity = "";
try
{
SAXReader saxReader = new SAXReader();
    Document document = saxReader.read(new BufferedInputStream(
                                                    new FileInputStream(
                                                   new File(path))));
    HashMap xmlMap = new HashMap();  
            xmlMap.put("mo","http://www.xxxx.com");  
            XPath x = document.createXPath("//mo:string"); //child node 
            x.setNamespaceURIs(xmlMap);           
            Element valueElement = (Element)x.selectSingleNode(document); 
            String flights = valueElement.getText();
           
            StringTokenizer loop = new StringTokenizer(flights,"^");
           
            while(loop.hasMoreTokens())
            {   
           
            flight = new Flights();
            StringTokenizer deep = new StringTokenizer(loop.nextToken(),","); 
                flight.setTakeOffDate(deep.nextToken());
            flight.setTakeOffTime(deep.nextToken());
            flight.setArriveTime(deep.nextToken());
            flight.setAirCode(deep.nextToken());
            flight.setFlightNum(deep.nextToken());
            bunkList = deep.nextToken();//所有舱位信息
            takeOffCity = deep.nextToken();
            arriveCity = deep.nextToken();
       
            flight.setAirBunkInfoBeans(getBunkInfo(takeOffCity,arriveCity,flight.getAirCode(),bunkList));
            flight.setPlaneModel(deep.nextToken());
            flight.setInsurance(deep.nextToken());
            flight.setMeal(deep.nextToken());
            flight.setElectricTicketFlag(deep.nextToken());
           
            flight.setTotalTime(getTime(flight.getTakeOffTime(),flight.getArriveTime()));
           
            list.add(flight);    
            }
          
}catch(DocumentException es)
         {
       es.printStackTrace();
          }catch(IOException er)
          {
     er.printStackTrace();
          }
          return list;
               }
}

你可能感兴趣的:(数据结构,.net,xml,webservice,Security)