Reputation: 159
This is probably a simple error on my part but I'm having issues reading a string argument that begins with @ in the context of XML
.
For example:
program.exe file.xml @attribute
the @attribute
string is the attribute that I need to check for in a join:
var testjoin = from x in tree1 join y in tree2 on (string)x.Attribute(args[2]) equals (string)y.Attribute("Order") select x
but I keep throwing errors "name cannot begin with the '@' character..." from when I try to pass it directly to x.Attribute()
Would someone be able to help me solve this?
EDIT:
The XML
content of the file is irrelevant. This is for assignment purposes but it is a simple file of Customers that I am comparing with a file of Orders.
The header of the file is
<?xml version="1.0" encoding="utf-8"?>
The @attribute
was literally @CustomerID
and I cannot alter how it is passed into my program. I can alter how I process it, so if there is another method I can use to perform a join passing that in as an attribute, I can change that.
Upvotes: 2
Views: 751
Reputation: 26792
A "C# string literal" and a "command line argument" live in different worlds, they have nothing to do with each other.
A (verbatim or regular) string literal is evaluated at compile time by the C# compiler. The '@' sign is an escape character used for verbatim string literals that (a.o.) tells the compiler to treat certain characters literally instead of as escape characters. E.g. @"hello\tworld"
will compile into a string with an actual backslash followed by t
, while "hello\tworld"
turns \t
into a tab.
A command line argument is passed in at runtime, so it can not be treated as a string literal. Which makes it your responsibility to deal with the '@' character in your code.
Upvotes: 1