這裏是我的代碼:如果在SAX中設置setNamespaceAware(true),如何獲得「xmlns:XXX」屬性?
path = wsdlPath;
SAXParserFactory saxfac = SAXParserFactory.newInstance();
saxfac.setNamespaceAware(true);
saxfac.setXIncludeAware(true);
saxfac.setValidating(false);
SAXParser saxParser = saxfac.newSAXParser();
saxParser.parse(wsdlPath, this);
設置setNamespaceAware=true
後,我無法在方法public void startElement(String uri, String localName, String qName, Attributes attributes)
的參數attributes
的xmlns:XXX
屬性。
以下節點:
<definitions name="Service1"
targetNamespace="http://www.test.com/service"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:tns="http://www.test.com/">
我只是得到name
和targetNamespace
屬性。 xmlns
,xmlns:wsdl
,xmlns:mime
,xmlns:http
和xmlns:tns
在attributes
參數中。但他們無法訪問。
有什麼方法可以使用setNamespaceAware=true
並獲得節點的所有屬性?
它的作品!許多許多感謝你! – DeepNightTwo 2011-03-24 09:24:23
我嘗試使用這個建議,發現我也必須做以下操作:'saxfac.setFeature(「http://xml.org/sax/features/namespaces」,false);' – 2011-04-06 17:05:57