Link to home
Start Free TrialLog in
Avatar of JHalstead
JHalsteadFlag for United States of America

asked on

Processing Instructions in XML

I need to read in the Processing instruction from an XML file and place it in a variable...

XML:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<doc>
    .....................................................................
</doc>

I need to read the href attribute out of the xml-stylesheet element.
Avatar of drichards
drichards

If this is in a file, then here's one way to get it:

      System.Xml.XmlTextReader rdr = new System.Xml.XmlTextReader("<filename>");
      while ( rdr.Read() )
      {
            if ( rdr.NodeType == System.Xml.XmlNodeType.ProcessingInstruction )
            {
                  // rdr.Value has 'type="text/xsl" href="test.xsl"' - parse out what you need
                  // rdr.Name has 'xml-stylesheet'
            }
      }
ASKER CERTIFIED SOLUTION
Avatar of drichards
drichards

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JHalstead

ASKER

It's works great, thanks, one question though.  rdr.Value returnes both the HREF and the TYPE, I would liek to return just the HREF.  I was thinking of creating an XML node from this returned info and selecting the HREF attribute, but I thought you might know an easier way.
Ok, never mind I got that part, it was easier than I though.