Saves the configuration data as XML.

Namespace: Nimsoft.NimBUS.Configuration
Assembly: NimbusAPI (in NimbusAPI.dll) Version: 1.6.4478.21958 (1.6.0.0)

Syntax

C#
public void SaveAsXml(
	string output,
	bool overwrite,
	bool makeIdAttributes
)
Visual Basic
Public Sub SaveAsXml ( _
	output As String, _
	overwrite As Boolean, _
	makeIdAttributes As Boolean _
)
Visual C++
public:
void SaveAsXml(
	String^ output, 
	bool overwrite, 
	bool makeIdAttributes
)

Parameters

output
Type: System..::..String
The name of the file to write XML formatted data to.
overwrite
Type: System..::..Boolean
if true, output will be overwritten if it already exists.
makeIdAttributes
Type: System..::..Boolean
if true, ID attributes will be created if certain conditions are met. See remarks and example.

Remarks

If an exception is thrown, use the Code property of the NimException to determine the cause of the exception. Possible ErrorCode values are:

  • FileWrite -
  • FileAlreadyExists -

If Code is FileCreate or FileWrite, the InnerException property of the NimException can be examined to further determine the cause of the exception. The inner exception will in this case be a .NET Exception caused by the file operation.

FileAlreadyExists is used if the output file exists and overwrite is false.

Parameters will be saved as attrubutes. See ConvertToXml(String, String, Boolean).

ID Attributes: If the section name contains a '-', e.g, section-1, and the section does not contain a key named "ID", "Id", or "id", the XML section name will be truncated to the substring before '-' and an attribute name "id" with a value equal to the substring after '-'. Spaces are trimmed. See example. Only performed if makeIdAttributes is true.

Note: The keys and sections of the original configuration file must be XML-convertable for this method to work, i.e., they can not contain illegal characters such as '<' and '>'.

Examples

Consider a standard NimBUS configuration file named "configurationdata.cfg" with the following content:
CopyC#
<section-12>
   name = Test
   value = 3.14
   <subsection>
      answer = 42 
   </subsection>
</section-1>
<section-2>
   id = 1
   company = Nimsoft  
</section2>
CopyC++
<section-12>
   name = Test
   value = 3.14
   <subsection>
      answer = 42 
   </subsection>
</section-1>
<section-2>
   id = 1
   company = Nimsoft  
</section2>
CopyVB.NET
<section-12>
   name = Test
   value = 3.14
   <subsection>
      answer = 42 
   </subsection>
</section-1>
<section-2>
   id = 1
   company = Nimsoft  
</section2>
The code below will save it as XML:
CopyC#
...
FileConfig config = new FileConfig("configurationdata.cfg");
config.SaveAsXml("configurationdata.xml", true, true);
...
CopyC++
...
FileConfig^ config = gcnew FileConfig("configurationdata.cfg");
config->SaveAsXml("configurationdata.xml", true, true);
...
CopyVB.NET
...
Dim config As FileConfig = New FileConfig("configurationdata.cfg")
config.SaveAsXml("configurationdata.xml", True, True)
...
The output will be
CopyC#
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <section
    id="12"
    name="Test"
    value="3.14">
    <subsection
      answer="42" />
  </section>
  <section-2
    id="1"
    company="Nimsoft" />
</configuration>
CopyC++
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <section
    id="12"
    name="Test"
    value="3.14">
    <subsection
      answer="42" />
  </section>
  <section-2
    id="1"
    company="Nimsoft" />
</configuration>
CopyVB.NET
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <section
    id="12"
    name="Test"
    value="3.14">
    <subsection
      answer="42" />
  </section>
  <section-2
    id="1"
    company="Nimsoft" />
</configuration>
Note that the makeIdAttributes parameter is set to true in this example.

Exceptions

ExceptionCondition
Nimsoft.NimBUS..::..NimException Thrown if a file operation fails, or the file can not be converted. See remarks.

See Also