The XMLCreator class is a class designed to assist in creating XML-documents. It wraps the MXXMLWriter30 class from microsoft and produces in-memory XML-documents as well as documents saved to disk.
The great thing about this class is that it takes care of the encoding of special characters etc.
Be the first to leve a comment or ask a question about the code!
Requires:
"Microsoft XML, v3.0" or later
"Microsoft ActiveX Data Objects 2.5 Library" or later
Here is an example how to use it:
Dim x As clsXMLCreator
Set x = New clsXMLCreator
x.Encoding = "UTF-8"
x.NewDocument
x.NewElement "Test"
x.AddAttribute "Version", 1
x.AddElement
x.NewElement "Persons"
x.AddElement
x.NewElement "Person"
x.AddAttribute "FName", "John"
x.AddAttribute "EName", "Doe
x.AddAttribute "DOB", "1999-01-01"
x.AddElement
x.SetElementValue "This is the first unknown person"
x.EndElement
x.NewElement "Person"
x.AddAttribute "FName", "Jean"
x.AddAttribute "EName", "Doe"
x.AddAttribute "DOB", "1999-02-02"
x.AddElement
x.EndElement
x.EndElement
x.EndElement
x.EndDocument
MsgBox x.GetDocument
The interface:
- Encoding as string
Property for setting and getting the encoding used in the resulting XML-document. Default is UTF-16.
- Standalone as boolean
Property for enabeling and disableing the standalone attribute in the XML-declaration. Default is True.
- OutputEscaping as boolean
Property for enabling and disableing the output escaping. Default is True.
- Indent as boolean
Property for enableing and disableing indentation of the resulting XML-document. Default is True.
- XMLDeclaration as boolean
Property for enableing and disableing the XML-declaration in the resulting XML-document. Default is True .
- NewDocument()
Starts a new document.
- EndDocument()
Ends a document.
- NewElement(ElementName as String)
Creates a new XML-element with the name ElementName.
- SetElementValue(Value as string)
Sets the value in the current XML-element.
- AddElement()
Adds a created element to the XML-document.
- EndElement()
Ends an added element.
- AddAttribute(AttributeName as string, AttributeValue as string)
Adds an attribute to a created element.
- GetDocument() as string
Returns the XML-document as a string.
- SaveDocument(FileName as string)
Saves the XML-document to a file.