Delete XML Element from SQL Table - sql

In the following XML, there are two Elements that I wish to delete. The Elements I wish to delete are tagged as <Files> How would I go about doing this?
<FooSource xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="FooFileTriggerSource">
<Files>keepThisFile.txt</Files>
<Files>deleteThisFile1.txt</Files>
<Files>deleteThisFile2.bat</Files>
</FooSource>

Related

how to use biml offline schema

I have defined a table in BIML that does not exists.
I then create the table using ExecuteSQL, and want to load that table.
However BIML will fail as it tries to query the non existent table.
I have already provided the column mapping so it doesnt need to query the table anymore.
This thread Create table before the dataflow in BIML mentions the offline schema, but there is not much content on how to use it.
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Metadata>
<OfflineSchema Name="OfflineSchema1">
<Items>
<Item Name="[Schema].[Table]" ConnectionName="ConnName">
<ExternalTableSource Table="[Schema].[Table]" />
</Item>
</OfflineSchema>
</Metadata>
</Biml>

MS SQL Server loading XML Source with multiple elements in database table

I'm relatively new to SQL Server, so please bear with me!
I have a XML file with multiple elements that I am trying to load into a database table, see below:
<ReportStatus>
<Change>
<Signatory>XXX</Signatory>
<Status>XXX</Status>
<StatusTime>XXX</StatusTime>
</Change>
<Message>
<CreationTime>XXX</CreationTime>
<ID>XXX</ID>
<Version>0.0.1</Version>
</Message>
<Request>
<References>
<Reference>
<RefId>Reference</RefId>
<RefValue>XXX</RefValue>
</Reference>
</References>
<RequestNr>XXX</RequestNr>
<Service>
<Name>XXX</Name>
<Type>XXX</Type>
</Service>
</Request>
The flow will only let me load one element at one time, I have tried loading the data into the table as such:
However, this loads the data into the table in 2 separate records:
Is there a way to consolidate these 2 elements before placing them into the table so the entire record is loaded as a single record?
Thanks in advance!
EDIT
Here's the table with the matching fields:

Edit XML data and import to SQL table

I have an XML feed from a wholesaler that is updated periodically to show the stock quantities of the items they wholesale. I need some help in collecting that XML file data twice a day and importing it into the SQL table on my website. Here is an example of the XML file:
<?xml version='1.0' encoding='ISO-8859-1'?>
<!DOCTYPE stockreport SYSTEM
'http://www.wholesalewebsite/feeds/status.dtd'>
<stockreport>
<timestamp>14/07/2014 18:55:26</timestamp>
<version>2.0</version>
<products>
<product type="main">
<code>M0507</code>
<name>Example Product</name>
<stock>4</stock>
<status>In Stock</status>
</product>
</products>
</stockreport>
I need to use this feed to update the quantities of the items in my store. My SQL table is called prods_stock and in the table the code (M0507) is called customid and stock is called quantity, so I need to alter the XML fields to match my existing table fields and then update the quantities using the customid(code) as an anchor point. I can ignore name and status.
How would I go about doing this?
Thanks in advance
Thanks for the suggestions, as I am not very good with coding etc... I have decided to just manually insert an sql query daily to update the database. An example of the code I will use is:
UPDATE products_stock SET customid = 'n12',quantity = 10 WHERE 1=1 AND customid= 'n12';
UPDATE products_stock SET customid = 'n50',quantity = 10 WHERE 1=1 AND customid= 'n50';
I will be using a csv feed file from the wholesaler and getting the info from there. Is there an easier/quicker way to drag the info from the csv file and update the table, rather than manually type the code for each line?
Thanks
You may have a look at XSLT. That allows you to parse any XML file and transform it's contents into any form you like. Using that you could transform the XML into SQL queries and run them agains the database.
You could then write a small shell script that loads the XML file, runs the XST-rules and hands the result on to the database.
You cannot archive that without any programming knowledge, but XSLT ist quite simple for such simple use cases. First I would work through a basic XSLT tutorial to become familar with the basics and then try it out with our problem.
Happy learning.. :)

Making XML according to XML Schema from data taken from SQL VIEW

Soon i will be doing xml file from my database according to given XML schema in .xsd file. I made it before but on simple tables with elements with no children. Now, schema is not that simple. Element has chilren and they also got it's children. I don't know how i can map data from my database into xml using that xml schema. For simple data it was very easy. I loaded schema and used it during creating xml file and giving fields from database names of tags in .xsd file. What happens when we got complex elements in schema? How can i map field from database into 3rd lvl elements?

Inserting Data from XML nodes into Database via SSIS

I want to insert the below XML Data retrieved from web service task into my Database,
<?xml version="1.0" encoding="utf-16"?>
<Data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Name xmlns="http://Iycon.com/WebService">Rahul</Name>
<BirthDate xmlns="http://Iycon.com/WebService">1988-09-23T00:00:00</BirthDate>
</Data>,
I am making use of foreach loop container to loop through different nodes but unable to get the result, this data I am inserting into database via Execute SQL Task, I have tried lot but unable to find solution,Thank You,
You can try the following to get the data into SQL Server.
Add Webservice Task
This retrieves the complete node set from the web service.
Update a variable(object) with the web service response data.
Add Data Flow Control
Add XML Source Control
Use XML from variable and generate the XSD
Add OLE Destination Control
Map your columns to match the XML nodes exposed from the XML Source.