Passing & as a parameter in string

Posted on 2009-04-21
Last Modified: 2012-05-06
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
Question by:subhorachana

    Author Comment

    it is in c# programming zone.
    LVL 20

    Expert Comment

    It was not- I added it there when I posted the above message :)
    It was only in Microsoft Development, Programming Languages
    LVL 21

    Expert Comment

    Could we see some sample code?

    Possibly the full stack trace?

    Author Comment

    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>"
    LVL 23

    Accepted Solution

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now