Parse XML with XML LINQ
Select Xml.Linq and work with names, elements and documents within the implemented subset.
Select XML LINQ
set(SHARP_RUNTIME_COMPONENTS Xml.Linq)
target_link_libraries(app PRIVATE SharpRuntime::Xml.Linq)
Model
Xml.Linq provides LINQ-style XML names, nodes, elements and documents over the project’s XML implementation. Xml and Xml.Linq have mutual binary needs, which is why XPath remains an alias rather than another physical archive.
Parse and navigate
#include <iostream>
#include "System/Xml/Linq/XElement.hpp"
using System::Xml::Linq::XElement;
int main()
{
auto catalog = XElement::Parse(
"<catalog><book id=\"sr\">Sharp Runtime</book></catalog>");
auto book = catalog->Element("book");
if (!book) return 1;
const auto id = book->getAttributeValue("id");
if (!id || *id != "sr") return 2;
std::cout << book->getValueProperty() << '\n';
return 0;
}Built and run
Against the pinned source, this prints Sharp Runtime and exits successfully.
Guidance
- Treat namespace-qualified names explicitly; current parse/serialization is not a full namespace-URI parity surface.
- Keep parent/child ownership and document lifetime in mind; do not retain borrowed views across owner destruction.
- Prefer owning
Attributes()results when data must outlive the element. - Do not assume a full XPath extension engine; variables and custom functions are outside the current subset.
External type exposure
The Xml target publicly exposes vendored tinyxml2 because a public header uses its types. This is an intentional component-visibility decision.