byteOrderMark Property

MSXML 5.0 SDK

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

byteOrderMark Property

Determines whether to write the Byte Order Mark (BOM) to MXXMLWriter output. Setting the byteOrderMark property to False prohibits the writer from putting the Byte Order Mark (BOM) into the resulting XML document or document fragment. This property is useful for creating document fragments. Setting this property to True makes MXXMLWriter follow XML 1.0 specifications and output the Byte Order Mark for appropriate encoding.

[Visual Basic]

Usage Syntax

oMXXMLWriter.byteOrderMark = boolValue
boolValue = oMXXMLWriter.byteOrderMark

Remarks

Boolean. Read/write. The default is True. MXXMLWriter never generates a BOM if the output is set to a string.

[C/C++]

Syntax

[proput]
HRESULT byteOrderMark (
   [in] VARIANT_BOOL fWriteByteOrderMark);
[propget]
HRESULT byteOrderMark (
   [out, retval] VARIANT_BOOL * fWriteByteOrderMark);

Parameters

fWriteByteOrderMark
A Boolean expression (True/False) specifying whether the feature is on or off.

Return Values

S_OK
The value returned if no errors are reported.

Remarks

The default of this is True. MXXMLWriter never outputs BOM if the output is set to a string.

Value Description
True MXMXLWriter follows XML 1.0 specifications and outputs BOM for encoding.
False MXMXLWriter does not write the BOM into the resulting XML output.

Example

In some cases, you may want to merge an XML document fragment with an XML document. If the document fragment has not been parsed, the "&" character will be escaped as "&" in the document fragment. However, if you merge the document fragment into an XML document, the "&" will be escaped again when it is parsed. To avoid the situation in which an already escaped character is escaped again, set the disableOutputEscaping property to True. The following code sample manually generates an XML document to demonstrate how this works. For the first element created, disableOutputEscaping is left as False, resulting in a double-escaped character. However, in the second element generated, disableOutputEscaping is set to True, enabling the "GG&G" value to be passed through as intended.

Dim wrt As New MXXMLWriter50
Dim cnth As IVBSAXContentHandler
Dim atrs As New SAXAttributes50
Set cnth = wrt

'Starts the document by addding the XML declaration.
cnth.startDocument
       
'This section escapes the character.
cnth.startElement "", "", "company", atrs
cnth.characters "GG&G"
cnth.endElement "", "", "company"

'This section passes the escaped character through as a literal.
wrt.disableOutputEscaping = True
cnth.startElement "", "", "company", atrs
cnth.characters "GG&G"
cnth.endElement "", "", "company"


'Ends the document.
cnth.endDocument
           
'Sets the writer output to the TextResult.Text box.
MsgBox wrt.output

Example Output

The output in the message box is as follows. Notice that the "&" character has been escaped twice in the first <company> element and passed through as intended (shown in bold) in the second <company> element.

<?xml version="1.0" encoding="UTF-16" standalone="no"?>

<company>GG&amp;amp;G</company>

<company>GG&amp;G</company>

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

See Also

Applies to: MXXMLWriter CoClass