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.
JHalsteadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

drichardsCommented:
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'
            }
      }
0
drichardsCommented:
Oops, that was C# code, here's the VB:

        Dim rdr As System.Xml.XmlTextReader = New System.Xml.XmlTextReader("..\\..\\..\\CSConsole\\XmlFile1.xml")
        While (rdr.Read())
            If (rdr.NodeType = System.Xml.XmlNodeType.ProcessingInstruction) Then
                System.Console.WriteLine(rdr.Name + " " + rdr.Value)
            End If
        End While
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JHalsteadAuthor Commented:
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.
0
JHalsteadAuthor Commented:
Ok, never mind I got that part, it was easier than I though.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.