Grabbing Certain Parts of XML Stored in DB - ASP.NET - c#

In my database I have a column that stores XML data, the database items are accessed through my model. However I need to be able to access specific items within the XML column, and convert them into a string to be used on my web page, what's the best way of doing this?
Example:
<DATAROW AgreementNumber="0000000" LoanAmount="£0.00" LoanTerm="20"
Title="Miss" FirstName="Joe" LastName="Bloggs"/>

Related

Store data of multiple parsed XML files - .NET

I've been working on a VB application which parses multiple XML files, and create an Excel file from them.
The main problem of this is that I am, simply, reading each line of each XML and outputs them to the Excel file when a specific node is found. I would like to know if exists any method to store the data from each element, just to use it once everything (all the XML files) have been parsed.
I was thinking about databases but I think this is excessive and unnecesary. Maybe you can give me some ideas in order to make it working.
System.Data.DataSet can be used as an "in memory database".
You can use a DataSet to store information in memory - a DataSet can contain multiple DataTables and you can add columns to those at runtime, even if there are already rows in the DataTable. So even if you don't know the XML node names ahead of time, you can add them as columns as they appear.
You can also use DataViews to filter the data inside the DataSet.
My typical way of pre-parsing XML is to create a two-column DataTable with the XPATH address of each node and its value. You can then do a second pass that matches XPATH addresses to your objects/dataset.

C# translate database data using resx file

In my project (I am using azure storage) I have some data that I want to translate. I have the resource system in place for translations. I have a table in cloud which has name property. I want to translate it somehow.
One option is to create all the entries in database for each language which I don't prefer as it would create a lot entries along with the name.
Is there a smart way to use the resx mechanism I have in place?
So the table has multiple properties and one is name. Name could be anything like Mud, rock etc. Now I want to translate Mud into different language. Something like Texts.Mud would return me the correct value.
But lets say I get data like this
var data = some query;
string translatedName = Texts.data[0].name; // this won't work
You should instead add more columns in the database, each for a different language and select the column based on the user language.
Other solution is to have a transaltion mechanism (a custom class for example), where you pass the original database result (say data[0].name) to a query and it returns the translated value for you.

Reading a string formatted like XML

I have a string that is written out like an XML file. An example would look like this:
string = <Employees><EmployeeId>1</EmployeeId>< ... ></Employees>
I am saving this in a table because I wanted to audit changes, but I didn't want to have multiple tables for different audits. This is because it would record changes to things other than employees. So using an XML style string in the database seemed like a good suggestion.
Now to the real business. I want to check to make sure that there were actually changes to the employee because one could go into the edit page, change nothing, and click save. As of right now, the data would write to the DB and just clutter it up with non-changed data.
I'd like to be able to check if the XML styled string that is going to be saved is on the database, so if <employees><employeeid>###</employeeid> == "changes" and then see if the whole string equals the other. Basically, check the employeeId first because that won't change, and then check the string as a whole to see if there is any difference. I would have just checked the first n numbers, but the id number could have a length of 1 to 3.
Also, because it is styled as XML, is there an easy way to convert it to read it like an XML file and check that way?
Storing arbitrary data in a column is a form of denormalization. You can't really do much with it at a database level. However, SQL Server does have an XML column type. Entity Framework doesn't support mapping to/from an XML column, so it will simply treat your XML as a standard string. With this column type, though, you can write actual SQL queries against your XML using XPath expressions.
Your best bet, then, is to type your column as XML, and then write a stored procedure that performs the query you need. You can then utilize this stored procedure with Entity Framework.
For more information on the XML column type see: https://msdn.microsoft.com/en-us/library/ms190798(SQL.90).aspx

SharePoint Web Service XML - Lookup columns bringing ;#

When I am using the Lists.asmx webservice to bring out List data, the xml thus generated comes back with list lookup columns with data that look like this: [135;#Superman]
Is there a way to get rid of the Number;# and just leave Superman?
You can try:
Console.WriteLine(Regex.Match("1236;#xxl", "\d+;#(.*)").Groups[1]);
Or use any other string manipulation

what is the best way to manage application user options in C# and sql?

My application has dozens of ComboBoxes filled with lists of values.
I wonder what is the best way to store these values in the DB since the user can add/remove :
Store in XML in Sql Server ?
Store in a text file on the server ?
any best practice ?
Thanks
John
I would keep track of them in a table on SQL server. If a user can define each field, then you simply need a table with a field name, value, and userid. Then you can extrapolate all of it from there.
Of course, you would want to use a key of some kind linked to a table that defines each type of field possible, if needed.
One row per key/value (combobox) should do the trick.
Another option to consider is to serialize your form in a json string that you'll store in a table in the SQL server DB. That way, you'll only have one entry per user to read. Then, you can deserialize the json string in an object that retains the properties of each control.
The big advantage of doing it this way is that if your form changes (and changes do happen!) you won't have to modify the data layer (ie. table definition + query).

Categories

Resources