SAML getUnmarshaller(element) 返回 null

我正在尝试从 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>";

任何帮助,将不胜感激。


不负相思意
浏览 351回答 2
2回答

慕侠2389804

我不知道它是否仍然需要但是DefaultBootstrap.bootstrap();一开始就为我解决了这个问题。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java