Link to home
Start Free TrialLog in
Avatar of gautam_reddyc
gautam_reddyc

asked on

Web service to Upload XML string to DB : gets error

I have a web service that accepts the xml string and uploads to the database..

  [WebMethod]
        public void Service(string XML)
        {
            try
            {
                using (DBDataContext db = new DBDataContext())
                {
                    db.ImportXML(XElement.Parse(XML));
                }

               
            }
            catch (Exception err)
            {
               
                throw err;
            }
        }

iam getting the below error
HTTP Transport error javax.xml.soap.SOAPException Error parsing envelope: (77,40) Invalid char in Text.

i know it is occurning beceause of some invalid characters in the xml string..
is there any other way to do it.. can anyone help.

also what do i need to do if i need to upload 100mb data..
Avatar of alexey_gusev
alexey_gusev
Flag of United Kingdom of Great Britain and Northern Ireland image

first of all, you should detect what character is invalid.

in general, you might want to encode your xml string before sending it to ws
Line 77, character 40 would be were I would start.

At a guess, you have a < or a >.
Avatar of gautam_reddyc
gautam_reddyc

ASKER

the special characters are # and &..
we are on the web service side.. we have no control of what is being sent as input.. how do we parse it
replace xml special chars (like < by &amp;gt;)
If it is a real soap service, then you reject it. It isn't valid XML and that's a requirement.

Can you show the node with the bad chars?

# doesn't ring any bells as far as I know.

& => &amp;

Unless you have something like ...

&#123; and you want that as the 6 characters, rather than { it represents.

In that case ...

&amp;#123; should be used.

Again, it isn't your concern normally as this is bad data.

it is in the comments tag
 <COMMENT>Item #1089 building </COMMENT>.. there are bunch of comments tag..
how to replace all.. any idea?
i know this is a bad data.. but we need to parse the entire xml string. identify all the special characters and replace them with good data..
ASKER CERTIFIED SOLUTION
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Works like a charm.. thanks..buddy