471,594 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

System.XML Migration - Corresponding System.XML object for MSXML IXMLDOMSelection

Hi there,

I was trying to convert the following VB6 code to VB.NET. But I can't find
a corresponding System.XML object for MSXML IXMLDOMSelection.

I am thinking to use System.XML XMLNodeList object and GetElementsByTagName
method
to find the "selection". Any suggestion/comment?

Thanks in advance.

Abel

Example:
---------------------------------------------------------------
Dim xmlStatic As New MSXML2.DOMDocument
xmlStatic.loadXML (strXMLString)

Dim objSelection As IXMLDOMSelection
Set objSelection = xmlStatic.selectNodes("//Reading")

For i = 0 To objSelection.length - 1
....
next i

....
---------------------------------------------------------------

Nov 12 '05 #1
3 4770
Hi Abel,
Thanks for posting in the community!
From your description, you are looking for some suggestions on using the
XmlNodeList class in System.Xml namespace to perform the same as the
IXMLDOMSelection component in MSXML COM component, yes?
If there is anything I misunderstood, please feel free to let me know.

Based on my research, you may use the XmlNodeList together with the
XmlDocument class's SelectNodes method( in fact ,this method also avaliable
on the XmlNode class) which can return a XmlNode Array via the XPath you
provided as param. For example, here is a generic code snippet:

----------------------------------------------------------------
private void button6_Click_1(object sender, System.EventArgs e)
{

try
{
String xmlString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Events>" +
"<event><MySession date=\"date_0_0\" time=\"time_0_0\"
location=\"location_0_0\" /><MySession date=\"date_0_1\" time=\"time_0_1\"
location=\"location_0_1\" /></event>" +
"<event><MySession date=\"date_1_0\" time=\"time_1_0\"
location=\"location_1_0\" /></event>" +
"<event><MySession date=\"date_2_0\" time=\"time_2_0\"
location=\"location_2_0\" /><MySession date=\"date_2_1\" time=\"time_2_1\"
location=\"location_2_1\" /></event></Events>";

XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlString);
XmlNodeList events = doc.SelectNodes("//Events/event");

for(int i=0;i<events.Count;i++)
{
XmlNode evt = events[i];
XmlNodeList sessions = evt.SelectNodes("MySession");
for(int j=0;j<sessions.Count;j++)
{
string msg = "session\n";

foreach(XmlAttribute att in sessions[j].Attributes)
{
msg += att.Name + att.Value + "\n";
}
MessageBox.Show(msg);
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}

----------------------------------------------------------

In addition, here are some tech references on the XmlNodeList and
XmlDocument's SelectNodes method in MSDN:

#XmlNode.SelectNodes Method (String)
http://msdn.microsoft.com/library/en...xmlxmlnodeclas
sselectnodestopic1.asp?frame=true

#Select Nodes Using XPath Navigation
http://msdn.microsoft.com/library/en...ctnodesusingxp
athnavigation.asp?frame=true

#XML Document Object Model (DOM)
http://msdn.microsoft.com/library/en...ocumentObjectM
odelDOM.asp?frame=true

Please check out the above items to see whether they help.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 12 '05 #2
Yes, you are correct on COM component.

I think your suggested XmlNodeList and SelectNodes should work.

By the way, do you have a copy of Side-By-Side MSXML to System.XML
Reference?

I can't find it anywhere in MS or in the WEB.

Thanks a lot.

Abel.


"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:6H*************@cpmsftngxa06.phx.gbl...
Hi Abel,
Thanks for posting in the community!
From your description, you are looking for some suggestions on using the
XmlNodeList class in System.Xml namespace to perform the same as the
IXMLDOMSelection component in MSXML COM component, yes?
If there is anything I misunderstood, please feel free to let me know.

Based on my research, you may use the XmlNodeList together with the
XmlDocument class's SelectNodes method( in fact ,this method also avaliable on the XmlNode class) which can return a XmlNode Array via the XPath you
provided as param. For example, here is a generic code snippet:

----------------------------------------------------------------
private void button6_Click_1(object sender, System.EventArgs e)
{

try
{
String xmlString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Events>" +
"<event><MySession date=\"date_0_0\" time=\"time_0_0\"
location=\"location_0_0\" /><MySession date=\"date_0_1\" time=\"time_0_1\"
location=\"location_0_1\" /></event>" +
"<event><MySession date=\"date_1_0\" time=\"time_1_0\"
location=\"location_1_0\" /></event>" +
"<event><MySession date=\"date_2_0\" time=\"time_2_0\"
location=\"location_2_0\" /><MySession date=\"date_2_1\" time=\"time_2_1\"
location=\"location_2_1\" /></event></Events>";

XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlString);
XmlNodeList events = doc.SelectNodes("//Events/event");

for(int i=0;i<events.Count;i++)
{
XmlNode evt = events[i];
XmlNodeList sessions = evt.SelectNodes("MySession");
for(int j=0;j<sessions.Count;j++)
{
string msg = "session\n";

foreach(XmlAttribute att in sessions[j].Attributes)
{
msg += att.Name + att.Value + "\n";
}
MessageBox.Show(msg);
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}

----------------------------------------------------------

In addition, here are some tech references on the XmlNodeList and
XmlDocument's SelectNodes method in MSDN:

#XmlNode.SelectNodes Method (String)
http://msdn.microsoft.com/library/en...xmlxmlnodeclas sselectnodestopic1.asp?frame=true

#Select Nodes Using XPath Navigation
http://msdn.microsoft.com/library/en...ctnodesusingxp athnavigation.asp?frame=true

#XML Document Object Model (DOM)
http://msdn.microsoft.com/library/en...ocumentObjectM odelDOM.asp?frame=true

Please check out the above items to see whether they help.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 12 '05 #3
Hi Abel,
Thanks for your response. As for the "copy of Side-By-Side MSXML to
System.XML Reference", I've searched the MSDN and other reference but
didn't find any very detailed mapping lists. However, there is a kb article
below discussing on implement common MSXML task using SYSTEM.XML namespace
classes in dotnet

#HOW TO: Implement Common MSXML Tasks in System.xml By Using Visual C# .NET
http://support.microsoft.com/?id=330589

Hope this helpful.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Keith Chadwick | last post: by
3 posts views Thread by Marius Trælnes | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.