yahoojapan / SwiftyXMLParser

Simple XML Parser implemented in Swift
MIT License
580 stars 89 forks source link

Is there a way to replace a text #62

Closed zhouhao27 closed 2 years ago

zhouhao27 commented 3 years ago

For example:

<a>
    <b>This is a test</b>
</a>

What should I do to replace the text This is a test? Thanks.

kazuhiro4949 commented 3 years ago

@zhouhao27 You can do it with 5.5.0

        let str = """
        <a>
            <b>This is a test</b>
        </a>
        """

        // parse xml document
        let xml = try! XML.parse(str)

        xml.a.b.element?.text = "That is a test"
        print(try! XML.Converter(xml).makeDocument(withDeclaration: false))
zhouhao27 commented 2 years ago

@kazuhiro4949 Wow, amazing. Tested. It's working. Thanks.