473,770 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String starting with ' won't concatenate

Some error handling code:

catch (System.Xml.Xml Exception e)
{
Console.WriteLi ne("Error in " + e.SourceUri + ": " + e.Message);
return;
}

The output:

' is an unexpected token. The expected token is '>'. Line 17, position 50.

Everything in the string before e.Message is deleted. I suspect that this is because the Message property starts with '. Is there a workaround for this?

Gustaf
Jul 26 '07 #1
11 2424
Gustaf wrote:
Some error handling code:

catch (System.Xml.Xml Exception e)
{
Console.WriteLi ne("Error in " + e.SourceUri + ": " + e.Message);
return;
}

The output:

' is an unexpected token. The expected token is '>'. Line 17, position 50.

Everything in the string before e.Message is deleted. I suspect that
this is because the Message property starts with '. Is there a
workaround for this?
What is the value of e.SourceUri, what is the value of e.Message? Your
suspicion is incorrect. Ex:

string uri = "http://www.uri.com/";
string message = "' is an unexpected token. The expected token is '>'.
Line 17, position 50.";
Console.WriteLi ne("Error in " + uri + ": " + message);

Outputs:

Error in http://www.uri.com/: ' is an unexpected token. The expected
token is '>'. Line 17, position 50.
--
Tom Porterfield
Jul 26 '07 #2
Tom Porterfield wrote:
What is the value of e.SourceUri, what is the value of e.Message?
The value of e.SourceUri is "file:///d:/test/po.xsd". The value of e.Message is the string starting with '. So the full output I expect is:

Error in file:///d:/test/po.xsd: ' is an unexpected token.
Line 17, position 50.

As soon as I use e.Message and it has this particular message (starting with '), it removes everything before the e.Message part.

If I add a string *after* e.Message, it stays there. Also, if I make it show another error (not starting with '), it works:

Error in file:///d:/test/po.xsd: The 'xs:element' start tag on
line 17 does not match the end tag of 'xs:element_'. Line 17,
position 52.

So I'm still convinced it's the ' in the beginning of e.Message that's causing it.

Gustaf
Jul 26 '07 #3
On Jul 26, 1:33 pm, Gustaf <gust...@algone t.sewrote:

<snip>
So I'm still convinced it's the ' in the beginning of e.Message that's causing it.
Can you produce a short but complete program which demonstrates the
problem?
See http://pobox.com/~skeet/csharp/complete.html for more details
about what I mean.

Jon

Jul 26 '07 #4
Gustaf wrote:
The value of e.SourceUri is "file:///d:/test/po.xsd". The value of
e.Message is the string starting with '. So the full output I expect is:

Error in file:///d:/test/po.xsd: ' is an unexpected token.
Line 17, position 50.

As soon as I use e.Message and it has this particular message (starting
with '), it removes everything before the e.Message part.

If I add a string *after* e.Message, it stays there. Also, if I make it
show another error (not starting with '), it works:

Error in file:///d:/test/po.xsd: The 'xs:element' start tag on
line 17 does not match the end tag of 'xs:element_'. Line 17,
position 52.

So I'm still convinced it's the ' in the beginning of e.Message that's
causing it.
Can you post a short but complete example that demonstrates the problem?
I am unable to reproduce the situation with the following:

string uri = "file:///d:/test/po.xsd";
try
{
string message = "' is an unexpected token. The expected token is
'>'. Line 17, position 50.";
System.Xml.XmlE xception ex = new XmlException(me ssage, null, 17, 50);
throw new System.Xml.XmlE xception(messag e);
}
catch (System.Xml.Xml Exception ex)
{
Console.WriteLi ne("Error in " + uri + ": " + ex.Message);
}

That shows the expected output.
--
Tom Porterfield
Jul 26 '07 #5
Jon Skeet [C# MVP] wrote:
Can you produce a short but complete program which demonstrates the
problem?
Not exactly short, but here goes...

1. Create a new console app, and paste in this code:

using System;
using System.Xml;
using System.Xml.Sche ma;

namespace XmlTest
{
class Program
{
static void Main(string[] args)
{
// Schema and XML file names
string uriOfSchema = @"d:\test\po.xs d";
string xmlToValidate = @"d:\test\po.xm l";

// Define XmlReader settings
XmlReaderSettin gs settings = new XmlReaderSettin gs();
settings.CheckC haracters = true;
settings.CloseI nput = true;

// Try reading schema
try
{
settings.Schema s.Add(null, uriOfSchema);
}
catch (System.Xml.Xml Exception e)
{
Console.WriteLi ne("Error in " + e.SourceUri + ": " + e.Message);
return;

/* NOTE: If e.Message starts with ', everything before e.Message is
* strangely removed. */
}

settings.Valida tionType = ValidationType. Schema;
settings.Valida tionFlags |= XmlSchemaValida tionFlags.Repor tValidationWarn ings;
settings.Valida tionEventHandle r += new ValidationEvent Handler(Validat ionCallBack);

try
{
using (XmlReader xmlReader = XmlReader.Creat e(xmlToValidate , settings))
{
if (xmlReader != null)
{
while (xmlReader.Read ());
Console.WriteLi ne("Validation completed.");
}
}
}
catch (Exception e)
{
Console.WriteLi ne(e.Message);
}
}

private static void ValidationCallB ack(object sender, ValidationEvent Args args)
{
switch (args.Severity)
{
case XmlSeverityType .Error:
Console.WriteLi ne("Error: " + args.Message);
break;
case XmlSeverityType .Warning:
Console.WriteLi ne("Warning: " + args.Message);
break;
}
}

}
}

2. Then make a file called po.xsd and paste in this code:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="a" type="xs:string "/
</xs:schema>

(There is an intentional well-formedness error on line 3.)

3. Put this file in a folder of your choice and correct the variable 'uriOfSchema' in the code. You won't need the XML file to run this test.

Gustaf
Jul 26 '07 #6
Gustaf wrote:
Tom Porterfield wrote:
>What is the value of e.SourceUri, what is the value of e.Message?

The value of e.SourceUri is "file:///d:/test/po.xsd". The value of
e.Message is the string starting with '. So the full output I expect is:

Error in file:///d:/test/po.xsd: ' is an unexpected token.
Line 17, position 50.

As soon as I use e.Message and it has this particular message (starting
with '), it removes everything before the e.Message part.
No, it doesn't. Just because you can't see that part on the screen when
the output is complete, doesn't mean that it's removed from the string,
and doesn't mean that it wasn't displayed om the screen.

The most likely explanation is that the message actually starts with a
carreage return character. That makes the cursor return to the beginning
of the line, and the message will overwrite the first part of the string.
If I add a string *after* e.Message, it stays there. Also, if I make it
show another error (not starting with '), it works:

Error in file:///d:/test/po.xsd: The 'xs:element' start tag on
line 17 does not match the end tag of 'xs:element_'. Line 17,
position 52.

So I'm still convinced it's the ' in the beginning of e.Message that's
causing it.
That conclusion is based on the assumption that you can actually see the
entire string when it has been written to the screen.

--
Göran Andersson
_____
http://www.guffa.com
Jul 26 '07 #7
On Jul 26, 3:05 pm, Gustaf <gust...@algone t.sewrote:
Can you produce a short but complete program which demonstrates the
problem?

Not exactly short, but here goes...
<snip>

The problem is that the second character of the message is a carriage
return.

Change your code to:

Console.WriteLi ne("Error in " + e.SourceUri + ": " +
e.Message.Repla ce("\r", "\\r"));

and you'll see what I mean.

Jon

Jul 26 '07 #8
Gustaf wrote:
Jon Skeet [C# MVP] wrote:
>Can you produce a short but complete program which demonstrates the
problem?

Not exactly short, but here goes...
As Jon says, you have a carriage return as the second character of
e.Message. An inspection of that in the debugger shows this.
--
Tom Porterfield
Jul 26 '07 #9
Jon Skeet [C# MVP] wrote:
The problem is that the second character of the message is a carriage
return.
Thank you both. So Message strings of .NET exception classes may contain whitespace other than SPACE? Does it mean it's generally good practice to normalize these strings before presenting them?

Gustaf
Jul 27 '07 #10

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

Similar topics

35
2469
by: michael.casey | last post by:
The purpose of this post is to obtain the communities opinion of the usefulness, efficiency, and most importantly the correctness of this small piece of code. I thank everyone in advance for your time in considering this post, and for your comments. I wrote this function to simplify the task of combining strings using mixed sources. I often see the use of sprintf() which results in several lines of code, and more processing than really...
3
2433
by: Locia | last post by:
I have a Template base class and another subclasses of Template. I have a tree structure of template object. class Template { ArrayList child; public virtual String Eval(Environment env) {
33
4690
by: genc_ymeri | last post by:
Hi over there, Propably this subject is discussed over and over several times. I did google it too but I was a little bit surprised what I read on internet when it comes 'when to use what'. Most of articles I read from different experts and programmers tell me that their "gut feelings" for using stringBuilder instead of string concatenation is when the number of string concatunation is more then N ( N varies between 3 to max 15 from...
34
2663
by: Larry Hastings | last post by:
This is such a long posting that I've broken it out into sections. Note that while developing this patch I discovered a Subtle Bug in CPython, which I have discussed in its own section below. ____________ THE OVERVIEW I don't remember where I picked it up, but I remember reading years ago that the simple, obvious Python approach for string concatenation: x = "a" + "b"
6
5802
by: Registered User | last post by:
Hi experts, I'm trying to write a program to solve the following exercise: Accept three strings from the user. Find the first occurrence of the first string in the third string. If it is present replace the second string in its place. Note: First and Second string might not be of the same length. E.g.: First string: "cat" Second string: "camel" Third string: "concatenate"
1
3060
by: kellysgirl | last post by:
Now what you are going to see posted here is both the set of instructions I was given..and the code I have written. The instructions I was given are as follows In this case, you will create a Visual Basic 2005 solution that manipulates strings. It will parse a string containing a list of items within a text box and put the individual items into the list box. It will build the textbox string by putting the list box items together into a...
7
8279
by: largedimples | last post by:
The assignment was as follows: A character string can be implemented as a linked list of characters. Implement a C++ ADT called Newstring that uses linked lists to implement the following string operations: display() // display private data on standard output length() // returns the length of string concatenate(Newstring)
13
21852
by: sinbad | last post by:
hi, how to concatenate a "hash defined" constant value to another "hash defined" constant string. For example #define ABC 100 #define MYSTR "The value of ABC is" Now i need a string that will concatenate the value of ABC to MYSTR . I need this at compile time.
6
3516
by: James Arnold | last post by:
Hello, I am new to C and I am trying to write a few small applications to get some hands-on practise! I am trying to write a random string generator, based on a masked input. For example, given the string: "AAANN" it would return a string containing 3 alphanumeric characters followed by 3 digits. This part I have managed:) I would now like to add some complexity to this, such as repetitions and grouping. For example, I'd like to have...
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10254
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10099
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8929
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.