From 49fa0f73e40cc80c2ddef5a72bd0f42bde0c6293 Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 19 May 2019 08:16:10 +0100 Subject: [PATCH] Added an overload to ValueTree::fromXml() which can take an XML string and parse it --- modules/juce_data_structures/values/juce_ValueTree.cpp | 8 ++++++++ modules/juce_data_structures/values/juce_ValueTree.h | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/modules/juce_data_structures/values/juce_ValueTree.cpp b/modules/juce_data_structures/values/juce_ValueTree.cpp index 76d0d6f461..e185d8d816 100644 --- a/modules/juce_data_structures/values/juce_ValueTree.cpp +++ b/modules/juce_data_structures/values/juce_ValueTree.cpp @@ -1015,6 +1015,14 @@ ValueTree ValueTree::fromXml (const XmlElement& xml) return {}; } +ValueTree ValueTree::fromXml (const String& xmlText) +{ + if (auto xml = parseXML (xmlText)) + return fromXml (*xml); + + return {}; +} + String ValueTree::toXmlString (const XmlElement::TextFormat& format) const { if (auto xml = createXml()) diff --git a/modules/juce_data_structures/values/juce_ValueTree.h b/modules/juce_data_structures/values/juce_ValueTree.h index 3b649d470e..1145a68aee 100644 --- a/modules/juce_data_structures/values/juce_ValueTree.h +++ b/modules/juce_data_structures/values/juce_ValueTree.h @@ -438,6 +438,12 @@ public: */ static ValueTree fromXml (const XmlElement& xml); + /** Tries to recreate a tree from its XML representation. + This isn't designed to cope with random XML data - it should only be fed XML that was created + by the createXml() method. + */ + static ValueTree fromXml (const String& xmlText); + /** This returns a string containing an XML representation of the tree. This is quite handy for debugging purposes, as it provides a quick way to view a tree. @see createXml()