?
Solved

Web service to Upload XML string to DB :  gets error

Posted on 2010-09-07
11
Medium Priority
?
752 Views
Last Modified: 2012-06-21
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..
0
Comment
Question by:gautam_reddyc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 24

Expert Comment

by:alexey_gusev
ID: 33624859
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
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 33625787
Line 77, character 40 would be were I would start.

At a guess, you have a < or a >.
0
 

Author Comment

by:gautam_reddyc
ID: 33627821
the special characters are # and &..
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:gautam_reddyc
ID: 33627870
we are on the web service side.. we have no control of what is being sent as input.. how do we parse it
0
 
LVL 24

Expert Comment

by:alexey_gusev
ID: 33627938
replace xml special chars (like < by &amp;gt;)
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 33628115
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.

0
 

Author Comment

by:gautam_reddyc
ID: 33628168
it is in the comments tag
 <COMMENT>Item #1089 building </COMMENT>.. there are bunch of comments tag..
how to replace all.. any idea?
0
 

Author Comment

by:gautam_reddyc
ID: 33628186
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..
0
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 2000 total points
ID: 33628655
Not being rude, but good luck.

What criteria makes "bad data"?

That's why we have a parser to do this for us. It is inordinately complicated.

In essence you need to parse every character to determine if it < is for / or just some orphaned < in the middle of nowhere.

#1089 really shouldn't be an issue.

<?xml version="1.0"?>
#1089

is perfectly valid.

But ...

Assuming you CAN get hold of the XML before it gets to the parser ...

Using the regex ...

>(?![\r\n]++)([^<]*?)(?![\r\n]++)<(?![\r\n]++)([^<]*?)(?![\r\n]++)<

could work.


Dim ResultString As String
Try
	ResultString = Regex.Replace(XMLString, ">(?![\r\n]+)([^<]*?)(?![\r\n]+)<(?![\r\n]+)([^<]*?)(?![\r\n]+)<", ">$1&lt;$2<", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
Catch ex As ArgumentException
	'Syntax error in the regular expression
End Try

Open in new window

0
 

Author Closing Comment

by:gautam_reddyc
ID: 33649928
Works like a charm.. thanks..buddy
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 33649998
Woo Hoo!
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

718 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