【问题标题】:How to build HierarchicalConfiguration object from xml string content?如何从 xml 字符串内容构建 HierarchicalConfiguration 对象?
【发布时间】:2021-03-04 12:59:44
【问题描述】:

我有 xml 字符串内容,它作为请求正文的一部分传递给 rest API,

<?xml version="1.0" encoding="UTF-8"?>
<sdp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="repository://schemas/sdp-config.xsd">
<helpPage>/mstinc/sdp/help/index.html</helpPage>
<ib>
    <siteUrl>/onlineserv/HB/</siteUrl>
    <startUpPage>
        <sdpUrl>SECONDARY~PRIMARY_BUTTON_ACCOUNT_ACCESS.NAME~ACCOUNT_ACCESS_SECONDARY_BUTTON_SDP.NAME</sdpUrl>
        <otherUrl>SECONDARY~PRIMARY_BUTTON_ACCOUNT_ACCESS.NAME~ACCOUNT_ACCESS_SECONDARY_BUTTON_ACCOUNT_SUMMARY.NAME</otherUrl>
        <axisConfValue>true</axisConfValue>
    </startUpPage>
 </ib>

我想构建 HierarchicalConfiguration 对象,以便我可以遍历键使用,

Iterator keys = {hierachicalObject}.getKeys();

我不想创建文件,因为内容是为每个请求动态传递的。我该怎么做?

【问题讨论】:

    标签: java xml apache-commons-config


    【解决方案1】:

    我认为您可以从 String 中的标记获取信息并使用此字符串。

    例如:

    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document doc = documentBuilder.parse(xmlFile);
            doc.getDocumentElement().normalize();
    String keys = doc.getElementsByTagName("sdpUrl").item(0).getTextContent();
    

    然后使用键。但是有用过的文件。 在那里您可以阅读如何从 String XML 获取数据:Read a XML (from a string) and get some fields - Problems reading XML

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-27
      • 1970-01-01
      • 1970-01-01
      • 2013-11-28
      • 2011-08-26
      • 2011-07-24
      • 1970-01-01
      相关资源
      最近更新 更多