Monday, 8 December 2014

remove type in xml while generating



I have 1000 records in text file. My requirement is to insert data into sql server. For that, if i can convert to xml or push to script component also fine.


Source Text file consists in this format...


[{"ID":1,:"Name":"test1","State":"AP"},{"ID":2,:"Name":"test2","State":"KN"}{"ID":3,:"Name":"test3","State":null}]



String json = System.IO.File.ReadAllText(@"C:\t1.txt");
byte[] bytes = Encoding.ASCII.GetBytes();
using (var stream = new MemoryStream(bytes))
{
var quotas = new XmlDictionaryReaderQuotas();
var jasonreader - JsonReaderWriterFactory.CreateJasonReader(stream,quotas);
var xml = XDocument.Load(jsonreader);
xmlDocument xd = new XmlDocument();

using (steamwriter fs = new streamwriter(@"C:\t.xml");
{
fs.write(xml);
}
console.writeLine(xml);
}


Output -



<root type="array"
<item type="object">
<ID type="number">1</ID>
<Name type="string">test1</Name>
<State type="string">AP</State>
</item>
<item type="object">
<root type="array"
<item type="object">
<ID type="number">2</ID>
<Name type="string">test2</Name>
<State type="string">KN</State>
</item>
<item type="object">
<root type="array"
<item type="object">
<ID type="number">3</ID>
<Name type="string">test3</Name>
<State type="string"></State>
</item>
</root>


When am using SSIS XML Source task, am getting columns...


External Columns: type text item_id


Output Columns: type text item_id


Ideally, i should get ID, Name, and State columns. What is the issue? How can I get rid of type in xml?


No comments:

Post a Comment