How to parse xml values

5 pts.
Tags:
.NET development
XML development
XML Parsing
I'm working on a console app that takes an xml file and groups the value of the errorMsg element into an output file (either to the console or to a txt file).  My issue is how to parse the value found within the errorMsg Element. (See file sample below).  what i need from each errorMsg element value is the table and column the error was generated from (i bolded the fields i need to group by in the xml sample below). Any help given is greatly appreciated. [!--?xml version="1.0" encoding="UTF-8"?--] [curr_transactions_set]   [curr_transactions_record]     [curr_transaction_id]10101[/curr_transaction_id]  [loadid]3010[/loadid]      [errormsg]java.sql.SQLException: The INSERT statement conflicted with the FOREIGN KEY constraint "CURR_TRANSACTIONS_FK20". The conflict occurred in database "PDLL", table "dbo.PA_SALES",column 'AGREEMENT_PST'.   ErrorCode=547   SQLSTATE=23000   Column:DIR_LABOR_FL_WA, Value:null   Column:DEPREC_CC_WA, Value:null   Column:DIROTFIX_CST_CC_WA, Value:null   Column:PHYS_ITS_VOLUME, Value:0.0000     Column:STORAGE_AND_HANDLING, Value:null       [/errormsg]    [/curr_transactions_record] [/curr_transactions_set]  

Software/Hardware used:
Visual Studio 2010, C#.net

Answer Wiki

Thanks. We'll let you know when a new response is added.

If all the messages are similar, then I would write a function that looks for the pattern:

… table ” — the word table, then a space, then a quote character

Then extract the following text up to the next quote character as the table name and repeat for the column name.

<pre>declare @i int;
declare @sTable varchar(255);
declare @sColumn varchar(255);

set @i = CHARINDEX( ‘table “‘, @sErrorMsg );
if @i > 0
begin
set @sTable = substring( @sErrorMsg, @i+7, 255 );
set @i = CHARINDEX( ‘”‘, @sTable );
if @i > 0
set @sTable = LEFT ( @sTable, @i – 1 );
end;</pre>

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Pdbrown70
    [...] A user is asking for help parsing XML: Kccrosser offer some advice. .topsy_widget_shortcode,div.topsy-sm {display:inline;} .post [...]
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following