5 pts.
 How to parse xml values
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
ASKED: October 27, 2011  1:46 PM
UPDATED: October 28, 2011  4:36 PM

Answer Wiki:
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>
Last Wiki Answer Submitted:  October 28, 2011  4:36 pm  by  Kccrosser   3,830 pts.
All Answer Wiki Contributors:  Kccrosser   3,830 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _