How to get XML Stream Namespace"

Sometimes I need to load a stream from a file in a Biztalk pipeline and I have to determine the Ty pe of the message.

Here s how i do that :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
    // This is for sample only. Should refer to the message stream and rewind the stream.

    Stream fs = new FileStream(filepath, FileMode.Open); 

    // End of stream initialisation.

    XPathDocument sourceDoc = new XPathDocument(fs);

    XPathNavigator navigator = sourceDoc.CreateNavigator();

    navigator.MoveToFirstChild();

    string streamDocSchema = navigator.NamespaceURI + "#" + navigator.LocalName;

    // Assigns the Namespace to the MessageType in context
    ...