• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 445
  • Last Modified:

Passing & as a parameter in string

I have a message in XML format and I am retreiving data from each element of the XML using XPATH in Biztalk.I am now passing this data as parameters where I want to do additional manipulation to the data.
One of my string parameter values is coming as "EK &SONS INC" and when I try to pass this as it is in string format in a method call, I get the following error: "System.Xml.XmlException: An error occurred while parsing EntityName"
I have even tried to replace the & with &
Please suggest what should  I do to format the string such that  the '&' is retained in the string and the method call is successful.
I am using C#.NEt for coding
1 Solution
subhorachanaAuthor Commented:
it is in c# programming zone.
It was not- I added it there when I posted the above message :)
It was only in Microsoft Development, Programming Languages
Could we see some sample code?

Possibly the full stack trace?
subhorachanaAuthor Commented:
exact location of code where I am getting the error:I am trying to create an XML as one of the parameter for Web service.It throws an error while creating the XML.
batchElement.InnerXml = "<Method ID='1' Cmd='New'>" +
               "<Field Name='Title'>APIS</Field>" +
               "<Field Name='Status'>Pending</Field>" +
              "<Field Name='Number'></Field>" +
              "<Field Name='EffecitveDate'>adsafsa</Field>" +
              "<Field Name='ExpirationDate'></Field>" +
              "<Field Name='Named'>EK &amp;SONS INC</Field>" +
              "<Field Name='NamedICity'>Chicago</Field>" +
              "<Field Name='NamedZIP'>60611</Field></Method>"
Tony McCreathTechnical SEO ConsultantCommented:
I would use the dom objects to add your elements instead of hand writing the XML as a string. This way the dom objects will make sure your text is encoded correctly and your xml is well formatted.
XmlElement methodElement = xmlDoc.CreateElement("Method");
XmlElement fieldElement = xmlDoc.CreateElement("Field");
fieldElement.InnerText = "EK &amp;SONS INC";

Open in new window


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now