You are trying to assign Stream object to String variable. You must read
the stream to that variable. This is how I do it:
Dim Assm As System.Reflection.Assembly = Me.GetType().Assembly
' Open the required resource and create stream from it.
Dim xmlStream As System.IO.Stream =
Assm.GetManifestResourceStream("MyAssemblyName" & "MyXmlFile.xml")
Dim reader As New System.IO.StreamReader(xmlStream)
Dim buffer As String = reader.ReadToEnd()
reader.Close()
xmlStream.Close()
The resulting string is in variable "buffer".

Signature
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
.NET and ASP .NET code
Hi Peter.
That was very helpful. Thanks very much for that. Unfortunately, the
variable buffer is a string and I need it returning in a format readable by
an XmlTextReader.
I have included your code as a function, which I assumed would be called
from the code below so that m_xmlr is assigned the returned value from the
function, which would be a variable of type XmlTextReader containing the
contents of the xml resource. How do you assign the resulting string to a
variable of a type readable by an XmlTextReader object, rather than as a
string. If I amend your code so that dim buffer as string becomes dim buffer
as XmlTextReader, I get build errors, "Value of type 'String' cannot be
converted to 'System.Xml.XmlTextReader'"
Here is part of my current code. This successfully reads the XML if
c:\VB.net\HotfixesNet\Hotfixes.xml exists. But on most target computers it
doesn't, hence the wish to embed the xml source in the app.
m_xmlr = New XmlTextReader("C:\vb.net\HotfixesNet\Hotfixes.xml") 'Create the
XML Reader
m_xmlr.WhitespaceHandling = WhitespaceHandling.None 'Disable whitespace so
that you don't have to read over whitespaces
m_xmlr.Read() 'read the xml declaration and advance to Hotfix tag
m_xmlr.Read() 'read the Hotfix tag
etc
etc.
What am I missing here?Thanks very much for your help
Regards,
John
> You are trying to assign Stream object to String variable. You must read
> the stream to that variable. This is how I do it:
[quoted text clipped - 9 lines]
>
> The resulting string is in variable "buffer".
Peter Macej - 23 Sep 2005 10:21 GMT
> variable buffer is a string and I need it returning in a format readable by
> an XmlTextReader.
XmlTextReader has a constructor which accepts Stream argument. So you
can easily create one:
Dim xmlStream As System.IO.Stream =
Assm.GetManifestResourceStream("MyAssemblyName" & "MyXmlFile.xml")
Dim m_xmlr As New XmlTextReader (xmlStream)
m_xmlr.WhitespaceHandling = WhitespaceHandling.None
m_xmlr.Read() 'read the xml declaration and advance to Hotfix tag
m_xmlr.Read() 'read the Hotfix tag
etc
etc.
m_xmlr.Close()
xmlStream.Close()
I haven't tried it but this should work. I parse XML using XmlDocument:
Dim doc As XmlDocument = New XmlDocument()
doc.LoadXml(bufferAsString)

Signature
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
.NET and ASP .NET code
John - 23 Sep 2005 15:41 GMT
Hi Peter,
That isn't doing it. When I try putting that on a button, I get "The
operation is not valid due to the current state of the object" as it trys to
run the m_xmlr.WhiteSpaceHandling = WhiltespaceHandling.None
This is what I'm trying to do:
OS = attrOS
m_xmlr = New XmlTextReader("C:\vb.net\HotfixesNet\Hotfixes.xml") 'Create the
XML Reader
m_xmlr.WhitespaceHandling = WhitespaceHandling.None 'Disable whitespace so
that you don't have to read over whitespaces
m_xmlr.Read() 'read the xml declaration and advance to Hotfix tag
m_xmlr.Read() 'read the Hotfix tag
While Not m_xmlr.EOF 'Load the Loop
m_xmlr.Read()
If m_xmlr.IsStartElement() Then 'if not start element exit while loop
m_xmlr.Read()
OSAttribute = m_xmlr.ReadString
m_xmlr.Read()
IDAttribute = m_xmlr.ReadString
m_xmlr.Read()
CDPathAttribute = m_xmlr.ReadString
m_xmlr.Read()
NetPathAttribute = m_xmlr.ReadString
m_xmlr.Read()
SwitchesAttribute = m_xmlr.ReadString
m_xmlr.Read()
TypeAttribute = m_xmlr.ReadString
If OSAttribute = OS And TypeAttribute = "Monthly" Then
intMonthly = intMonthly + 1
End If
If OSAttribute = OS And TypeAttribute = "New" Then
intNew = intNew + 1
End If
If OSAttribute = OS And TypeAttribute = "ITMU" Then
intITMU = intITMU + 1
End If
End If
StatusBar1.Text = "There are " + CStr(intMonthly) + " Monthly Hotfixes
and " + CStr(intNew) + " New Hotfixes available"
End While
m_xmlr.Close() 'close the reader
End Function
If I comment out the line that is failing, (m_xmlr.WhitespaceHandling =
WhitespaceHandling.None ) the app just seems to hang in debug.
This function counts the values of elements in the xml and stores values.
It works if the file exists in the path shown
("C:\vb.net\HotfixesNet\Hotfixes.xml")
What I'm trying to achieve is to access (reference) the embedded resourse
xml file instead of the file on the C Drive
I have several buttons which currently do similar things, i.e. access the
xml, read it in and perform actions based on entries in the xml. Each button
currently calls a different function which has broadly similar code in it.
The buttons pass a different attributes to their function.
I suppose it would also be nice to embed the actual call to xml into a
function which returns the contents of the xml file in a format that m_xmlr
can use without having to manipulate the returned data, it would really
simplify matters as I would be able to remove duplicate code from about 3 or
4 functions and replace it with calls the thefunction which returns the xml
file contensts in a format immediately accessible to m_xmlr. However, the
most important thing is to get the functions to reference the embedded
object rather than the one on the c drive
Sorry to hassle you about this, your help is much appreciated.
Regards,
John
>> variable buffer is a string and I need it returning in a format readable
>> by an XmlTextReader.
[quoted text clipped - 18 lines]
> Dim doc As XmlDocument = New XmlDocument()
> doc.LoadXml(bufferAsString)