Dealing with @ in ReadString

L

Laurel

I've written a function that might return multiple e-mail addresses. I've
been returning them in an XML string, and parsing it using ReadString, but I
get the error below. (Code for ReadString is also included).

Does anyone have any advice as to the best way to proceed?

1 - See if there's a way to "protect" the @ in the string - I've read the
documentation about using @ instead of quotes, but it will take some time
and effort to figure it out, and it may lead to nothing. Maybe ReadString
just can't do it?

2 - Use an array for the e-mail addresses instead of an XML string.

3 - Some other idea?

THE ERROR

The '@' character, hexadecimal value 0x40, cannot be included in a name.
Line 1, position 34.

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Xml.XmlException: The '@' character, hexadecimal
value 0x40, cannot be included in a name. Line 1, position 34.


THE CODE WHERE THE ERROR OCCURS

if (RecipientsReader.Name == "EmailRecipient")

{

strRecipient = RecipientsReader.ReadString().Trim(); //ERROR HAPPENS HERE

llReturn = QXTools.sendEmail(strEmail, strRecipient, "", "", strTitle,
strComments, "1", "0", "1" );
 
B

Bruce Wood

Laurel said:
I've written a function that might return multiple e-mail addresses. I've
been returning them in an XML string, and parsing it using ReadString, but I
get the error below. (Code for ReadString is also included).

Does anyone have any advice as to the best way to proceed?

1 - See if there's a way to "protect" the @ in the string - I've read the
documentation about using @ instead of quotes, but it will take some time
and effort to figure it out, and it may lead to nothing. Maybe ReadString
just can't do it?

2 - Use an array for the e-mail addresses instead of an XML string.

3 - Some other idea?

THE ERROR

The '@' character, hexadecimal value 0x40, cannot be included in a name.
Line 1, position 34.

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Xml.XmlException: The '@' character, hexadecimal
value 0x40, cannot be included in a name. Line 1, position 34.


THE CODE WHERE THE ERROR OCCURS

if (RecipientsReader.Name == "EmailRecipient")

{

strRecipient = RecipientsReader.ReadString().Trim(); //ERROR HAPPENS HERE

llReturn = QXTools.sendEmail(strEmail, strRecipient, "", "", strTitle,
strComments, "1", "0", "1" );

The problem would appear to be in your XML, not in your program. Could
you please post the XML in question?
 
J

Jon Skeet [C# MVP]

Laurel said:
I've written a function that might return multiple e-mail addresses. I've
been returning them in an XML string, and parsing it using ReadString, but I
get the error below. (Code for ReadString is also included).

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

It sounds like you're using the email address as an element or
attribute name. You can't do that - it's not valid XML. However, I
wouldn't like to go any further without knowing a bit more about what
you're actually doing.
 
J

Jon Skeet [C# MVP]

Laurel said:
This is cut and pasted directly from the debugger.

strRecipientsXML
"<ERP><EmailRecipient><[email protected]></EmailRecipient><Emai
lRecipient><[email protected]></EmailRecipient><EmailRecipient><la
(e-mail address removed)></EmailRecipient></ERP>"

Okay - you've currently got it as an element (and one that isn't
terminated, at that). Change it to just text content (or preferrably an
attribute):

<ERP>
<EmailRecipient address="(e-mail address removed)" />
<EmailRecipient address="(e-mail address removed)" />
<EmailRecipient address="(e-mail address removed)" />
</ERP>
 
L

Laurel

Thanks to all. Definitely a case of staring at something and not seeing the
simple answer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top