简体   繁体   中英

XmlPullParser - Get Node Content as XML String

I have an issue where I want to store the content of a node I am parsing using the XmlPullParser as a string for later parsing. However I can't see how to do this without iterating over the entire content and creating the string myself by creating the start tags etc.

I have read this question, however it is going about it in exactly the way I want to avoid (preferably).

Here is some example XML below.

<result mime="text/xml">
        <array>
            <item key="action">
                <str>testcustom</str>
            </item>
            <item key="examplearray">
                <array>
                    <item key="0">
                        <str>Item 0</str>
                    </item>
                    <item key="1">
                        <str>Item 1</str>
                    </item>
                    <item key="2">
                        <str>Item 2</str>
                    </item>
                </array>
            </item>
       </array>
</result>

My Question

So in this example, I want to get the contents of the result node as an xml string. I don't want to parse it I just want to store it as String for parsing at a later date.

If anyone has any better ideas please let me know.

The PullParser is not giving u that string. In fact the parser is acting like a point on the current token. In order to have the full content of a node - u would need to parse it. Parsing is then of course changing the position of the parser.

The kxml implementation provides a DOM like implementation which has an Element class. This one is giving handy methods for parsing the current element out of a XmlPullParser and also has a toString implementation.

http://www.kxml.org

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