PC Review


Reply
Thread Tools Rate Thread

C# / VB .Net language incompatibilities

 
 
Gary Dunne
Guest
Posts: n/a
 
      25th Aug 2004
Hi,

Sorry if this is deemed to be a cross post (I also posted to the
microsoft.public.xml)

(Using .NET 2003, VB, C# on a Win2k PC)

I'm trying to retrieve nodes from an XML doc by name. I have found that the
following code, when translated into C# works perfectly, but not when used
in VB. In the example below the "application" node returns a value when
accessed through the C# code but not with the VB code.

If I add a prefix to the namespace in the source XML doc e.g. Change
<application xmlns="http://MyCompanyName.co.uk/test/1.0.08/">
to <application xmlns:TEST="http://MyCompanyName.co.uk/test/1.0.08/">
then it works fine in both languages.

Does anyone have experience of this problem ?

Below are the code samples from both languages... followed by the XML
excerpt

Thanks

Gary


VB Code --

****

Imports System
Imports System.Xml
Module Module1

Sub Main()

Try
Dim oXmlDoc As New Xml.XmlDocument
Dim sFileName As String = "04231ESWM001240.xml"

oXmlDoc.Load(sFileName)

Dim nsmgr As XmlNamespaceManager = New
XmlNamespaceManager(oXmlDoc.NameTable)

nsmgr.AddNamespace("clps",
"http://MyCompanyName.co.uk/test/1.0.08")
nsmgr.AddNamespace("xsi",
"http://www.w3.org/2001/XMLSchema-instance")
nsmgr.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema")
nsmgr.AddNamespace("soap",
"http://schemas.xmlsoap.org/soap/envelope/")

Console.WriteLine("Def NS = " & nsmgr.DefaultNamespace)

Dim oNode As Xml.XmlNode
oNode = oXmlDoc.SelectSingleNode("//application", nsmgr)

If oNode Is Nothing Then
Console.WriteLine("The application object was not found")
Else
Console.WriteLine(oNode.InnerText)
End If


Finally
Console.WriteLine("Press a key to end")
Console.Read()
End Try
End Sub


and the C# version ****

using System;
using System.Xml;
namespace TestXML
{
class Class1
{
ry>
[STAThread]
static void Main(string[] args)
{
XmlDocument xmlRequest = new XmlDocument();
xmlRequest.Load(@"N:\04231ESWM001240.xml");
XmlNamespaceManager nsMgr = new XmlNamespaceManager(xmlRequest.NameTable);
nsMgr.AddNamespace("clps","http://MyCompanyName.co.uk/test/1.0.08/");
nsMgr.AddNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
nsMgr.AddNamespace("xsd","http://www.w3.org/2001/XMLSchema");
nsMgr.AddNamespace("soap","http://schemas.xmlsoap.org/soap/envelope/");
Console.WriteLine("nsMgr.DefaultNamespace: " + nsMgr.DefaultNamespace);
XmlNode applicationNode = xmlRequest.SelectSingleNode("//application",
nsMgr);
if (applicationNode == null)
{
Console.WriteLine("application not found");
}
else
{
Console.WriteLine(applicationNode.InnerText.Trim());
}
Console.WriteLine(">>>Press a key to end");
Console.ReadLine();
}
}
}

XML *****

<?xml version="1.0"?>
<AppRoot xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<application xmlns="http://MyCompanyName.co.uk/test/1.0.08/">
<docid>04231ESWM001240</docid>
<applicationerror>false</applicationerror>
<HoldIndicator>false</HoldIndicator>
<field>
<name>TextReg1</name>
<text>STEP</text>
<error>false</error>
</field>
<field>
<name>portfolio_link_code</name>
<text>STEP</text>
<error>false</error>
</field>
</application>
</AppRoot>


 
Reply With Quote
 
 
 
 
Jeff Johnson [MVP: VB]
Guest
Posts: n/a
 
      25th Aug 2004

"Gary Dunne" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> Sorry if this is deemed to be a cross post (I also posted to the
> microsoft.public.xml)


Actually, to be technical, it's a multipost, which is very bad. Here's my
standard blurb to give you more info:

You have posted this question individually to multiple groups. This is
called Multiposting and it's BAD. Replies made in one group will not be
visible in the other groups, which may cause multiple people to respond to
your question with the same answer because they didn't know someone else had
already done it. This is a waste of time.

If you MUST post your message to multiple groups, post a single message and
select all the groups (or type their names manually, separated by commas) in
which you want it to be seen. This is called Crossposting and when used
properly it is GOOD.

(This isn't just my opinion. Look here:
http://www.oakroadsystems.com/genl/unice.htm#xpost)


 
Reply With Quote
 
Gary Dunne
Guest
Posts: n/a
 
      25th Aug 2004
er.... okay ..sorry

And for anyone that's interested ... the answer was ... there was a typo in
the namespace url. The ns specified in the XML source doc was
<application xmlns="http://capita.co.uk/clps/1.0.08/">
whereas in the VB code it was ...
nsmgr.AddNamespace("clps", "http://MyCompanyName.co.uk/test/1.0.08")

There was a forward slash missing from the VB call - should have been
nsmgr.AddNamespace("clps", "http://MyCompanyName.co.uk/test/1.0.08/")

Gary


 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      25th Aug 2004
Hi Gary,

Thanks for replying this, because I would get finding out what was wrong.

And for the rest had set the same sentence as Jeff about crossposting.

:-)

Cor

> er.... okay ..sorry
>
> And for anyone that's interested ... the answer was ... there was a typo

in
> the namespace url. The ns specified in the XML source doc was
> <application xmlns="http://capita.co.uk/clps/1.0.08/">
> whereas in the VB code it was ...
> nsmgr.AddNamespace("clps", "http://MyCompanyName.co.uk/test/1.0.08")
>
> There was a forward slash missing from the VB call - should have been
> nsmgr.AddNamespace("clps", "http://MyCompanyName.co.uk/test/1.0.08/")
>
> Gary
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vista Incompatibilities? Ross M. Greenberg Windows Vista General Discussion 1 18th Jan 2009 05:42 PM
Existing incompatibilities Martin Cleaver Windows Vista Installation 2 7th Dec 2006 07:44 AM
RDP and SP2 Incompatibilities? =?Utf-8?B?anN1bW1heg==?= Windows XP Help 1 12th Jan 2005 07:29 AM
RDP and SP2 Incompatibilities? =?Utf-8?B?anN1bW1heg==?= Windows XP Help 0 11th Jan 2005 03:59 PM
MYIE2 incompatibilities? Adam Freeware 1 22nd Aug 2003 01:33 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:34 PM.