Can we convert text file to xml via Business Rule

HoneyGulati
New Contributor III

Hi,

Can someone suggest if the text file can be converted into xml file via business rule?

1 ACCEPTED SOLUTION

MarcusH
Contributor III

An XML file is already a text file but in a particular format. It can be done through business rules - select the source file, process it and save it with an XML extension. You will need to know the XML structure. Then you can use XmlDocument to create the file. Here is a quick sample for creating the XML file:

Imports System.Xml

	' Create an XML document
	Dim xmlDoc As New XmlDocument()

	' Create the declaration
	Dim declaration As XmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", Nothing)
	xmlDoc.AppendChild(declaration)

	' Create the root element
	Dim myReport As XmlElement = xmlDoc.CreateElement("OECD")
	xmlDoc.AppendChild(myReport)

	' Add attributes to the root element
	myReport.SetAttribute("version", "2.0")

	' Create and append the ReportingEntity element
	Dim reportingEntity As XmlElement = xmlDoc.CreateElement("ReportingEntity")
	myReport.AppendChild(reportingEntity)

	Dim fileFullName As String = "C:\Temp\MyFile.xml"
	' Save the XML document to a file
	xmlDoc.Save(fileFullName)

 

View solution in original post

2 REPLIES 2

MarcusH
Contributor III

An XML file is already a text file but in a particular format. It can be done through business rules - select the source file, process it and save it with an XML extension. You will need to know the XML structure. Then you can use XmlDocument to create the file. Here is a quick sample for creating the XML file:

Imports System.Xml

	' Create an XML document
	Dim xmlDoc As New XmlDocument()

	' Create the declaration
	Dim declaration As XmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", Nothing)
	xmlDoc.AppendChild(declaration)

	' Create the root element
	Dim myReport As XmlElement = xmlDoc.CreateElement("OECD")
	xmlDoc.AppendChild(myReport)

	' Add attributes to the root element
	myReport.SetAttribute("version", "2.0")

	' Create and append the ReportingEntity element
	Dim reportingEntity As XmlElement = xmlDoc.CreateElement("ReportingEntity")
	myReport.AppendChild(reportingEntity)

	Dim fileFullName As String = "C:\Temp\MyFile.xml"
	' Save the XML document to a file
	xmlDoc.Save(fileFullName)

 

HoneyGulati
New Contributor III

Thanks @MarcusH It helps