All was well with my code in the tracer-bullet version that used POX, but then I added the XSL and I can no longer use .Element("anything")
Here’s my xml document:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*|@*">
<xsl:apply-templates select="*|@*" />
</xsl:template>
<xsl:template match="CO">
<html>
<head>
<title>My Page</title>
</head>
<body></body>
</html>
</xsl:template>
</xsl:stylesheet>
This throws a null reference exception:
templateDoc.Root.Element("body").Add(newElements);
because .Element("body") is null. templateDoc is an XDocument object that has been properly loaded with the XML above using: XDocument.Load(filePath);
What do I need to do in order to be able to do find the body node here?
You need to specify namespace.
OR