我正在尝试从 XmlString 构造 XML 对象,但 getUnmarshaller(element) 返回 null :这是代码: try { InitializationService.initialize(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = docBuilder.parse(new ByteArrayInputStream(xmlString.trim().getBytes())); Element element = document.getDocumentElement(); UnmarshallerFactory unmarshallerFactory = XMLObjectProviderRegistrySupport.getUnmarshallerFactory(); org.opensaml.core.xml.io.Unmarshaller unmarshaller = unmarshallerFactory .getUnmarshaller(element); //This is coming out be null System.out.println(unmarshaller); } catch (Exception e) { e.printStackTrace(); }这是 XMLStringstatic String xmlString ="<?xml version=\"1.0\"?>" + " <!DOCTYPE address" + " [" + " <!ELEMENT address (buildingnumber, street, city, state, zip)>" + " <!ATTLIST address xmlns CDATA #IMPLIED>" + " <!ELEMENT buildingnumber (#PCDATA)>" + " <!ELEMENT street (#PCDATA)>" + " <!ELEMENT city (#PCDATA)>" + " <!ELEMENT state (#PCDATA)>" + " <!ELEMENT zip (#PCDATA)>" + " ]>" + "" + " <address>" + " <buildingnumber> 29 </buildingnumber>" + " <street> South Street</street>" + " <city>Vancouver</city>" + "" + " <state>BC</state>" + " <zip>V6V 4U7</zip>" + " </address>";任何帮助,将不胜感激。
添加回答
举报
0/150
提交
取消