Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

WordFile.GetXML

Queries xml content of the word file.

Component Version macOS Windows Linux Server iOS SDK
WordFile 6.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "WordFile.GetXML"; WordFile { ; Part } )   More

Parameters

Parameter Description Example Flags
WordFile The reference number of the open word file. $wordFile
Part The name of the part to query.
See WordFile.Parts for a list of parts.
if no part is given, we use the document.
"document" Optional

Result

Returns xml text or error.

Description

Queries xml content of the word file.
Getting the raw xml allows you to make modification yourself like adding paragraphs or a table.

Examples

Query XML of first footer:

MBS( "WordFile.GetXML"; $wordFile; "footer1" )

Query document relations:

MBS( "WordFile.GetXML"; $WordFile; "document.xml.rels")

Query custom properties of a word file:

# open word file
Set Variable [ $wordfile ; Value: MBS( "WordFile.OpenContainer"; WordFile::Input ) ]
If [ MBS("ISError") ]
    Show Custom Dialog [ "Error" ; $wordFile ]
    Exit Script [ Text Result: ]
End If
#
# read xml
Set Variable [ $xml ; Value: MBS( "WordFile.GetXML"; $WordFile; "custom") ]
#
# get property count
Set Variable [ $count ; Value: MBS( "XML.NodeCount"; $xml; "property" ) ]
#
If [ $count > 0 ]
    Set Variable [ $i ; Value: 0 ]
    #
    Loop
        Set Variable [ $name ; Value: MBS( "XML.GetPathValue"; $xml; "Properties.property[" & $i & "]#name"; 1+2 ) ]
        Set Variable [ $value ; Value: MBS( "XML.GetPathValue"; $xml; "Properties.property[" & $i & "].lpwstr"; 1+2 ) ]
        #
        Show Custom Dialog [ "Custom propety" ; $name & ": " & $value ]
        #
        Set Variable [ $i ; Value: $i + 1 ]
        Exit Loop If [ $i >= $count ]
    End Loop
    #
    #
End If
#
# free memory
Set Variable [ $r ; Value: MBS( "WordFile.Release"; $WordFile) ]

Change XML directly:

# get xml
Set Variable [ $xml ; Value: MBS( "WordFile.GetXML"; $wordfile) ]
# Change something
Set Variable [ $xml ; Value: Substitute($xml; "Times New Roman"; "Helvetica") ]
# put xml back
Set Variable [ $r ; Value: MBS( "WordFile.SetXML"; $wordfile; $xml) ]

See also

Release notes

  • Version 9.5
    • Improved WordFile.GetXML function to work with rels parts in the Word file.

Blog Entries

This function checks for a license.

Created 15th March 2016, last changed 29th December 2021


WordFile.GetMediaFile - WordFile.HasTag