Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - SAX2 Reference

omitXMLDeclaration Property

Forces the IMXWriter to skip the XML declaration. This can be useful when you want to output fragments of larger XML documents that can be assembled into a single XML document later.

[Visual Basic]

Implementation Syntax

Property Let IMXWriter_omitXMLDeclaration(ByVal RHS As Boolean)
Property Get IMXWriter_omitXMLDeclaration() As Boolean

Usage Syntax

oMXXMLWriter.omitXMLDeclaration= boolValue
boolValue = oMXXMLWriter.omitXMLDeclaration

Remarks

Read/write. A Boolean expression (True/False) specifying whether the feature is on or off. The omitXMLDeclaration property has no effect on DOM output.

[C/C++]

Syntax

[propput]
HRESULT omitXMLDeclaration (
   [in] VARIANT_BOOL fValue);
[propget]
HRESULT omitXMLDeclaration (
   [out, retval] VARIANT_BOOL * fValue);

Parameters

fValue
Boolean.

Return Values

S_OK
The value returned if no errors are reported.

Remarks

Value Description
True Omit XML declaration.
False (default) Provide XML declaration.

The omitXMLDeclaration property has no effect on DOM output.

The IXSLProcessor object implements the omitXMLDeclaration property as follows:

[Visual Basic]

Example

The following example loads the books.xml file and generates an XML document without the XML declaration.

XML File

Use books.xml.

Visual Basic File (Form1.frm)

Private Sub Command1_Click()
   Dim rdr As New Msxml2.SAXXMLReader50
   Dim cnth As IVBSAXContentHandler
   Dim wrt As New MXXMLWriter50
   wrt.indent = True
   wrt.omitXMLDeclaration = True
   wrt.byteOrderMark = False
   Set cnth = wrt
   Set rdr.contentHandler = cnth
   rdr.parseURL ("books.xml")
   MsgBox wrt.output
End Sub

Try It!

  1. Go to books.xml. Copy it to a folder on your computer (such as c:\temp).
  2. Open Visual Basic and create a new Standard EXE project.
  3. Create a reference in the project to Microsoft XML, v5.0.
  4. Add a command button (Command1) to the application form (Form1).
  5. From the View menu, click Code.
  6. Use copy and paste to replace any code in the form with the code provided above.
  7. Save the project and form to the folder on your computer where you saved books.xml in Step 1.
  8. From the Run menu, click Start.
  9. In the test application, click Command1 (the command button).

Output

When run, the sample Visual Basic application should display the books.xml with the XML declaration omitted from the output.

To view reference information for Visual Basic or C/C++ only, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

MXHTMLWriter CoClass | MXXMLWriter CoClass | Sample XML File (books.xml)

Applies to: IMXWriter Interface