简体   繁体   中英

How to build HierarchicalConfiguration object from xml string content?

I have xml String content which is passed as part of request body in 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>

I would like to build HierarchicalConfiguration object so that i can iterate through keys using,

Iterator keys = {hierachicalObject}.getKeys();

I don't want to create a file as the content is passed dynamically for each request. How can i do it?

I think you can get information from the tag in String and work with this string.

For example :

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

And after that working with keys. But there used file. There you can read how to get data from String XML : Read a XML (from a string) and get some fields - Problems reading XML

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM