LibXML+LibWeb: Store the XML document's original source

Similar to how we store an HTML document's original source. This allows
the source to be inspected with "View Source" in the Browser.
This commit is contained in:
Timothy Flynn 2022-11-03 09:43:34 -04:00 committed by Linus Groh
parent e7412717b4
commit b10bbac061
Notes: sideshowbarker 2024-07-17 04:50:07 +09:00
4 changed files with 8 additions and 0 deletions

View file

@ -46,6 +46,11 @@ XMLDocumentBuilder::XMLDocumentBuilder(DOM::Document& document, XMLScriptingSupp
{
}
void XMLDocumentBuilder::set_source(String source)
{
m_document.set_source(move(source));
}
void XMLDocumentBuilder::element_start(const XML::Name& name, HashMap<XML::Name, String> const& attributes)
{
if (m_has_error)

View file

@ -29,6 +29,7 @@ public:
bool has_error() const { return m_has_error; }
private:
virtual void set_source(String) override;
virtual void element_start(XML::Name const& name, HashMap<XML::Name, String> const& attributes) override;
virtual void element_end(XML::Name const& name) override;
virtual void text(String const& data) override;

View file

@ -174,6 +174,7 @@ ErrorOr<void, ParseError> Parser::parse_with_listener(Listener& listener)
{
m_listener = &listener;
ScopeGuard unset_listener { [this] { m_listener = nullptr; } };
m_listener->set_source(m_source);
m_listener->document_start();
auto result = parse_internal();
if (result.is_error())

View file

@ -29,6 +29,7 @@ struct ParseError {
struct Listener {
virtual ~Listener() { }
virtual void set_source(String) { }
virtual void document_start() { }
virtual void document_end() { }
virtual void element_start(Name const&, HashMap<Name, String> const&) { }