diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index 0c50c05..65719b1 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -204,6 +204,20 @@ s{PG_VERSION_STR "[^"]+"}{__STRINGIFY(x) #x\n#define __STRINGIFY2(z) __STRINGIFY
 		{
 			print O "#define HAVE_LIBXML2\n";
 			print O "#define USE_LIBXML\n";
+			
+			# Parse xmlversion.h to get version number
+			open(X,"$self->{options}->{xml}/include/libxml/xmlversion.h")
+			  || confess("Could not open xmlversion.h for reading\n");
+			while (<X>)
+			{
+				if (/^#define LIBXML_VERSION (.*)/)
+				{
+					print O "#define HAVE_XMLSTRUCTUREDERRORCONTEXT\n"
+					  if ($1 > 20703);
+					last;
+				}
+			}
+			close(X);
 		}
 		if ($self->{options}->{xslt})
 		{
