我正在尝试从 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();
}
这是 XMLString
static 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>";
任何帮助,将不胜感激。
慕侠2389804
相关分类