Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Value of Type String cannot be converted to System.xml.xmlDocument

568 views
Skip to first unread message

Rafael Dominguez

unread,
Jan 28, 2008, 2:11:38 AM1/28/08
to
All,

Using Visual Studio 2008 Professional trying to read an xml file and assign
the value (the file content) to a variable so that I can pass the variable
as an XML document to another function.

The code below tells me that I cannot convert a type string to a
system.xml.xmldocument.

Dim xmldoc As New Xml.XmlDocument
Dim rdr As New StreamReader("C:\Meeting\NewMeeting.xml", Encoding.UTF8)
xmldoc = rdr.ReadToEnd ' Value of Type String cannot be converted to
System.xml.xmlDocument

Any help will be appriciated!

Rafael

Micah Bell

unread,
Jan 30, 2008, 8:20:50 PM1/30/08
to
Well you could do this a number of ways, but this might get you started.

Dim myXMLDocument As New XmlDocument
Dim myXMLNodeList As XmlNodeList
Dim myXMLNode As XmlNode

myXMLDocument.Load("C:\test.xml")

myXMLNodeList = myXMLDocument.SelectNodes("/ParentNodeName/childNodeName")

For Each myXMLNode In myXMLNodeList
dim strTest as string = myXMLNode.Item("UserCredentials").InnerText
next

You can either loop through all the nodes or remove the For Each in which
you specify the record and item like
myXMLNOde(0).item(0).innertext

Hope that helps!

url:http://www.ureader.com/msg/15431163.aspx

Rafael Dominguez

unread,
Feb 5, 2008, 6:13:56 PM2/5/08
to
Thanks Michael. But my issue is complicated so here it goes.

I thought that was the extent of my problem but what's really at work here
is going from XDocument (LINQ format) to xml.xmlDocument (standard Visual
Studio xml DOM?).

I really like the new LINQ Queries to mange xml becuase being such a newbie,
I can understand it much better.

That said, I have not figured out a way to pull out the "outerXml" from an
xml doc using the new LINQ language. On the function below, the
GetBytes(xmldoc.OuterXml) part requires a regular DOM xml doc as the new
LINQ format does not support that particular feature. So if there's a way
to get something similar to an "OuterXml" from a linq xml doc, than I'm
golden.

Thanks,


public XmlDocument PostXmlMessageRequest(XmlDocument xmldoc)
{
// Upon entering, xmldoc = messageRequest
// Upon exit, xmlReply = messageReply;

ASCIIEncoding encoder = new ASCIIEncoding();
XmlDocument xmlReply = null ;

// Post the <messageRequest> element to the conference center;
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(postingUrl);
myReq.Method = "POST";
myReq.ContentType = "application/x-www-form-urlencoded";

HttpWebResponse myResp = null;
try
{
// Write the XML message to the request stream and
// send it to the conference center
byte[] byteArray = encoder.GetBytes(xmldoc.OuterXml);
myReq.ContentLength = byteArray.Length;
Stream reqStream = myReq.GetRequestStream();
reqStream.Write(byteArray, 0, byteArray.Length);
reqStream.Close();

// Get the response from the conference center
myResp = (HttpWebResponse)myReq.GetResponse();
Stream respStream = myResp.GetResponseStream();
if (myResp.ContentType == "application/xml")
{
xmlReply = new XmlDocument();
xmlReply.Load(respStream);
}
}
catch (Exception e)
{
// Log the error or implement other error handling routines
Console.WriteLine("Error: {0}\nStack trace: {1}",
e.Message, e.StackTrace);
}
finally
{
if (myResp != null)
myResp.Close();
}

return xmlReply;
}

"Micah Bell" <mb...@gmail.com> wrote in message
news:05b50f7ccae54719...@newspe.com...

Rafael Dominguez

unread,
Feb 5, 2008, 6:17:30 PM2/5/08
to
All, I'm user Visual Studio 2008/VSTO trying to read a DWORD registry value
which stores a user password and use to send an xml doc with httpWebRequest
as seen below. Wondering how to store and retrieve this kind of data from
the registry using VS.


http://msdn2.microsoft.com/en-us/library/bb894286.aspx
<PlaceWareConfCenter authUser="apiuser" authPassword="Pa$$w0rd">
<CreateMeetingRequest
maxUsers="100"
name="ShipParty"
title="Come to celebrate">
<OptionList>
<TimeOption name="startTime" value="2007-10-27T14:00:00Z"/>
<TimeOption name="endTime" value="2007-10-27T18:00:00Z"/>
<StringOption name="timeZone" value="America/Los_Angeles"/>
<EnumerationOption name="meetingType" value="OneTime" >
<String>OneTime</String>
<String>MeetNow</String>
<String>Recurring</String>
</EnumerationOption>
</OptionList>
<FieldList>
<Name>name</Name>
<Name>meetingType</Name>
<Name>mid</Name>
<Name>presenterPassword</Name>
<Name>audiencePassword</Name>
</FieldList>
</CreateMeetingRequest>
</PlaceWareConfCenter>


Thanks,

Rafael


"Micah Bell" <mb...@gmail.com> wrote in message
news:05b50f7ccae54719...@newspe.com...

0 new messages