Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Textual representation of children along with their attributes and text values #168

Closed
Tulakshana opened this issue Jan 4, 2018 · 4 comments

Comments

@Tulakshana
Copy link

Tulakshana commented Jan 4, 2018

Following is extracted from the xml I'm trying to serialized. I would like to retrieve the elements, attributes and text inside the element 'abody' in their textual format. What is the correct way to go about this?

<abody>
                    <anid>AN0113544370;vj901mar.16;2016Mar08.13:04;v2.2.500</anid>
                    <title id="AN0113544370-1">SOME TITLE </title>
                    <p>SOME TEXT</p>
                    <p>Some text 
                        <ulink href="some url">some linked text</ulink> some more text
                    <hd id="AN0113544370-2">EVENTS</hd>
                    <p>Some text</p>
                    <p>Some text</p>
                    <hd id="AN0113544370-3">LONDON</hd>
                    <p>Some text</p>
                    <p>Some text</p>
                    <p>Some text</p>
</abody>

I tried doing xml["abody"].element?.description. Then the string contains the 'abody' tag also. I only need its children.

Expected output,

                    <title id="AN0113544370-1">SOME TITLE </title>
                    <p>SOME TEXT</p>
                    <p>Some text 
                        <ulink href="some url">some linked text</ulink> some more text
                    <hd id="AN0113544370-2">EVENTS</hd>
                    <p>Some text</p>
                    <p>Some text</p>
                    <hd id="AN0113544370-3">LONDON</hd>
                    <p>Some text</p>
                    <p>Some text</p>
                    <p>Some text</p>
@drmohundro
Copy link
Owner

It sounds like what you're asking about is essentially an innerXML type of property that would be the string format. Is that correct? It might make sense to call it innerDescription or childrenDescription just to stay consistent with the existing description property, but I'm open to ideas.

Do you have any thoughts?

@Tulakshana
Copy link
Author

@drmohundro,
Yes, you got it right. I'm looking at something like an innerXML type of property. For the moment my work around is as follows,

        let body = xml['abody']
        var html = ""
        for child in body.children  {
                html += (child.element?.description ?? "")
        }

drmohundro added a commit that referenced this issue May 4, 2018
Behaves like innerHTML except for XML. Fixes #168.
@drmohundro
Copy link
Owner

@Tulakshana I just pushed #188 to add this feature... I'll plan on releasing it over the next few days, but if you'd like to check it out on my branch first to offer feedback, I'd welcome it! Thanks again for the suggestion!

@drmohundro
Copy link
Owner

FYI, I just published 4.7.0 to include this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants