[thelist] MSXML and processing instructions
David.Cantrell at Gunter.AF.mil
David.Cantrell at Gunter.AF.mil
Mon Dec 9 13:51:01 CST 2002
Is it possible to read processing instructions using the DOM? I don't need
to parse the contents, I can write string-munging VBScript for that. I just
need to actually retrieve the processing instruction itself as a string.
In the MSXML 4 Core Services SDK, under the topic "Targeted Processing
Instruction Tests", the following XPath is given:
/child::processing-instruction("xml-stylesheet")
Using this XPath in XSL returns the processing instruction contents (not the
<?..?> delimiters or the name, but the attributes as "key=value" pairs).
However, using this same XPath in the DOM fails.
Am I doing something wrong here? I understand PIs are outside the normal
DOM, which definitely explains why my SelectSingleNode() doesn't work, but
is there any other way to get at this value other than munging the entire
XML file as a string and using regular expressions? If that's the only
solution, it's not worth it... :P
Thanks!
-dave
Here's the code:
--- processing_instruction_test.asp ---
<%
Option Explicit
dim oXml : Set oXml = Server.CreateObject( "Msxml2.DomDocument.3.0" )
oXml.Load server.mappath( "processing_instruction_test.xml" )
dim oPi : Set oPi = oXml.SelectSingleNode(
"/child::processing-instruction(""xml-stylesheet"")" )
%>
--- processing_instruction_test.xml ---
<?xml-stylesheet type="text/xsl" href="processing_instruction_test.xsl"?>
<test>
<title>foo</title>
</test>
--- processing_instruction_test.xsl ---
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" cdata-section-elements="script"/>
<xsl:template match="/">
<h1><xsl:value-of
select="/child::processing-instruction('xml-stylesheet')"/></h1>
</xsl:template>
</xsl:stylesheet>
More information about the thelist
mailing list