473,320 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

C# / VB .Net language incompatibilities

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>
Nov 21 '05 #1
3 1234

"Gary Dunne" <Ke*****************@zarion.com.deletethis> wrote in message
news:e2**************@TK2MSFTNGP12.phx.gbl...
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)
Nov 21 '05 #2
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
Nov 21 '05 #3
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

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Peter Maas | last post by:
I tried to find a comprehensive list of Python backward incompatibilities without success. What is the fastest way to compile such a list (with code examples / expected results)? Thanks for your...
0
by: Thiva Charanasri | last post by:
http://www.poweroflanguage.org Track: Computer Language 1st World Congress on the Power of Language: Theory, Practice and Performance Date: March 6 - 10, 2006 Bangkok, Thailand On this...
22
by: Michael Nahas | last post by:
Antti & all interested, The draft description of my language to replace C is available at: http://nahas.is-a-geek.com/~mike/MyC.pdf I am a long time C programmer (I read the old testament...
134
by: evolnet.regular | last post by:
I've been utilising C for lots of small and a few medium-sized personal projects over the course of the past decade, and I've realised lately just how little progress it's made since then. I've...
0
by: Thiva Charanasri | last post by:
http://www.poweroflanguage.org Track: Computer Language 1st World Congress on the Power of Language: Theory, Practice and Performance Date: March 6 - 10, 2006 Bangkok, Thailand On this...
2
by: rjack | last post by:
I'm using VS 2005 Beta 2. In VS 2003, the Page directive in an aspx page has Language and CodeBehind attributes. You can have the language be different than the code behind file language. For...
35
by: John Coleman | last post by:
Greetings, I have a rough classification of languages into 2 classes: Zen languages and tool languages. A tool language is a language that is, well, a *tool* for programming a computer. C is the...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
10
by: Immortalist | last post by:
Various aquisition devices that guide learning along particular pathways towards human biases. And as E.O. Wilson might say mental development appears to be genetically constrained. (1) Language...
17
by: CoreyWhite | last post by:
I bought this book years ago, when I was just learning C++. Since then I've gone through every math course offered at my college, taken courses on coding C & thinking in terms how how to make the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.