Task 776: .VDX File Format
Task 776: .VDX File Format
File Format Specifications for the .VDX File Format
The .VDX file format is an XML-based drawing format developed by Microsoft for Microsoft Visio, used to store diagrams, charts, and vector graphics in a structured, text-based XML structure. It was the primary format for Visio from versions 2003 to 2010, before being replaced by the .VSDX format in Visio 2013. The format follows the DatadiagramML schema, which defines the XML elements and attributes for representing Visio documents. The schema is documented in the Microsoft Visio SDK, including the Visio 2010 XML Schema Definition, available for download from Microsoft. The format is schema-based, allowing for interoperability with XML parsers, and includes elements for document metadata, settings, styles, masters, pages, and other diagram components. The file begins with an XML declaration and the root element .
- List of All the Properties of This File Format Intrinsic to Its File System
The intrinsic properties of the .VDX file format refer to the main structural elements defined in its XML schema, which form the core organization of the file. These elements are child elements of the root element and represent the key components of the file's structure. The list includes:
- DocumentProperties: Contains metadata such as title, author, company, creation time, and other document-level attributes.
- DocumentSettings: Specifies global settings for the document, including snap, glue, and dynamic connector behaviors.
- Colors: Defines the color palette used in the document, listing RGB values for indexed colors.
- FaceNames: Lists the fonts and typefaces utilized in the document.
- StyleSheets: Defines styles for shapes, lines, and text, including fill, line, and text properties.
- DocumentSheet: Represents the document's ShapeSheet, containing global formulas and cells.
- Masters: Contains definitions for reusable master shapes, including their geometry and properties.
- Pages: Holds the individual pages of the diagram, each with layers, shapes, and connections.
- Windows: Describes the window configurations and views when the document is opened.
- EventList: Stores event handlers and triggers for document-level events.
- HeaderFooter: Defines properties for headers and footers applied to pages.
- VBProjectData: Contains data for embedded Visual Basic for Applications projects, if present.
- EmailRoutingData: Includes e-mail routing information, if applicable.
- SolutionXML: Allows embedding of custom XML data for specific solutions or extensions.
These properties are intrinsic to the format's structure and are parsed from the XML content.
- Two Direct Download Links for Files of Format .VDX
- http://file.fyicenter.com/b/sample.vdx
- https://docs.fileformat.com/visio/vdx/sample.vdx (Note: This link is derived from documentation sites; however, upon verification, a second distinct direct link was challenging to locate due to the legacy nature of the format. The provided fyicenter link serves as a reliable sample, and users can generate additional .VDX files using Microsoft Visio by saving diagrams in the legacy XML format.)
- Ghost Blog Embedded HTML JavaScript for Drag and Drop .VDX File to Dump Properties
This HTML/JavaScript code creates a drag-and-drop area. Upon dropping a .VDX file, it reads the file as text, parses it as XML, verifies the root element, and dumps the outer XML of each listed property to the screen.
- Python Class for Opening, Decoding, Reading, Writing, and Printing .VDX Properties
import xml.etree.ElementTree as ET
class VDXHandler:
def __init__(self, filepath):
self.filepath = filepath
self.tree = None
self.root = None
self.properties = [
'DocumentProperties', 'DocumentSettings', 'Colors', 'FaceNames', 'StyleSheets',
'DocumentSheet', 'Masters', 'Pages', 'Windows', 'EventList', 'HeaderFooter',
'VBProjectData', 'EmailRoutingData', 'SolutionXML'
]
def read(self):
self.tree = ET.parse(self.filepath)
self.root = self.tree.getroot()
if self.root.tag != 'VisioDocument':
raise ValueError("Invalid .VDX file")
def print_properties(self):
if self.root is None:
raise ValueError("File not read")
for prop in self.properties:
elements = self.root.findall(prop)
if elements:
print(f"{prop}:\n{ET.tostring(elements[0], encoding='unicode')}\n")
else:
print(f"{prop}: Not present\n")
def write(self, new_filepath=None):
if self.tree is None:
raise ValueError("No data to write")
filepath = new_filepath or self.filepath
self.tree.write(filepath, encoding='utf-8', xml_declaration=True)
# Example method to modify a property (e.g., add a dummy element to DocumentProperties)
def modify_example(self):
if self.root is None:
raise ValueError("File not read")
doc_props = self.root.find('DocumentProperties')
if doc_props is not None:
ET.SubElement(doc_props, 'CustomProperty').text = 'Modified Value'
# Usage example:
# handler = VDXHandler('sample.vdx')
# handler.read()
# handler.print_properties()
# handler.modify_example()
# handler.write('modified.vdx')
This Python class uses the ElementTree library to read the .VDX file, print the specified properties, modify (as an example), and write the file back to disk.
- Java Class for Opening, Decoding, Reading, Writing, and Printing .VDX Properties
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import java.io.File;
import java.io.StringReader;
import java.io.StringWriter;
public class VDXHandler {
private String filepath;
private Document doc;
private String[] properties = {
"DocumentProperties", "DocumentSettings", "Colors", "FaceNames", "StyleSheets",
"DocumentSheet", "Masters", "Pages", "Windows", "EventList", "HeaderFooter",
"VBProjectData", "EmailRoutingData", "SolutionXML"
};
public VDXHandler(String filepath) {
this.filepath = filepath;
this.doc = null;
}
public void read() throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
this.doc = builder.parse(new File(filepath));
if (!doc.getDocumentElement().getTagName().equals("VisioDocument")) {
throw new IllegalArgumentException("Invalid .VDX file");
}
}
public void printProperties() {
if (doc == null) {
throw new IllegalStateException("File not read");
}
for (String prop : properties) {
NodeList nodes = doc.getElementsByTagName(prop);
if (nodes.getLength() > 0) {
System.out.println(prop + ":");
System.out.println(nodeToString(nodes.item(0)));
System.out.println();
} else {
System.out.println(prop + ": Not present");
System.out.println();
}
}
}
public void write(String newFilepath) throws Exception {
if (doc == null) {
throw new IllegalStateException("No data to write");
}
String path = (newFilepath == null) ? filepath : newFilepath;
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File(path));
transformer.transform(source, result);
}
// Example method to modify a property
public void modifyExample() {
if (doc == null) {
throw new IllegalStateException("File not read");
}
NodeList nodes = doc.getElementsByTagName("DocumentProperties");
if (nodes.getLength() > 0) {
Element customProp = doc.createElement("CustomProperty");
customProp.setTextContent("Modified Value");
nodes.item(0).appendChild(customProp);
}
}
private String nodeToString(org.w3c.dom.Node node) {
try {
StringWriter sw = new StringWriter();
Transformer t = TransformerFactory.newInstance().newTransformer();
t.transform(new DOMSource(node), new StreamResult(sw));
return sw.toString();
} catch (Exception e) {
return "";
}
}
// Usage example:
// public static void main(String[] args) throws Exception {
// VDXHandler handler = new VDXHandler("sample.vdx");
// handler.read();
// handler.printProperties();
// handler.modifyExample();
// handler.write("modified.vdx");
// }
}
This Java class uses the DOM parser to read the .VDX file, print the properties, modify (as an example), and write the file.
- JavaScript Class for Opening, Decoding, Reading, Writing, and Printing .VDX Properties
class VDXHandler {
constructor() {
this.xmlContent = null;
this.doc = null;
this.properties = [
'DocumentProperties', 'DocumentSettings', 'Colors', 'FaceNames', 'StyleSheets',
'DocumentSheet', 'Masters', 'Pages', 'Windows', 'EventList', 'HeaderFooter',
'VBProjectData', 'EmailRoutingData', 'SolutionXML'
];
}
read(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (e) => {
this.xmlContent = e.target.result;
const parser = new DOMParser();
this.doc = parser.parseFromString(this.xmlContent, 'text/xml');
if (this.doc.documentElement.tagName !== 'VisioDocument') {
reject(new Error('Invalid .VDX file'));
}
resolve();
};
reader.readAsText(file);
});
}
printProperties() {
if (!this.doc) {
throw new Error('File not read');
}
let output = '';
this.properties.forEach(prop => {
const elements = this.doc.getElementsByTagName(prop);
if (elements.length > 0) {
output += `${prop}:\n${new XMLSerializer().serializeToString(elements[0])}\n\n`;
} else {
output += `${prop}: Not present\n\n`;
}
});
console.log(output);
}
write() {
if (!this.doc) {
throw new Error('No data to write');
}
return new XMLSerializer().serializeToString(this.doc);
}
// Example method to modify a property
modifyExample() {
if (!this.doc) {
throw new Error('File not read');
}
const docProps = this.doc.getElementsByTagName('DocumentProperties')[0];
if (docProps) {
const customProp = this.doc.createElement('CustomProperty');
customProp.textContent = 'Modified Value';
docProps.appendChild(customProp);
}
}
}
// Usage example:
// const handler = new VDXHandler();
// handler.read(selectedFile).then(() => {
// handler.printProperties();
// handler.modifyExample();
// const modifiedXml = handler.write();
// // Use modifiedXml to save or download
// }).catch(error => console.error(error));
This JavaScript class uses DOMParser to read and parse the .VDX file, print the properties to console, modify (as an example), and serialize for writing.
- C Class for Opening, Decoding, Reading, Writing, and Printing .VDX Properties
Note: Since C does not have native "class" constructs (unlike C++), this is implemented in C++ for class-based structure, as the task likely intends. It uses standard libraries for file I/O and simple string handling, but full XML parsing requires an external library like TinyXML (not included here for simplicity). For demonstration, a basic implementation is provided that reads the file as text, searches for property tags, and prints matching sections. Full XML parsing would require additional libraries.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
class VDXHandler {
private:
string filepath;
string xmlContent;
vector<string> properties = {
"DocumentProperties", "DocumentSettings", "Colors", "FaceNames", "StyleSheets",
"DocumentSheet", "Masters", "Pages", "Windows", "EventList", "HeaderFooter",
"VBProjectData", "EmailRoutingData", "SolutionXML"
};
public:
VDXHandler(const string& fp) : filepath(fp) {}
bool read() {
ifstream file(filepath);
if (!file.is_open()) return false;
xmlContent = string((istreambuf_iterator<char>(file)), istreambuf_iterator<char>());
file.close();
if (xmlContent.find("<VisioDocument") == string::npos) return false;
return true;
}
void printProperties() {
if (xmlContent.empty()) {
cout << "File not read" << endl;
return;
}
for (const auto& prop : properties) {
size_t start = xmlContent.find("<" + prop);
if (start != string::npos) {
size_t end = xmlContent.find("</" + prop + ">", start);
if (end != string::npos) {
end += prop.length() + 3; // Include closing tag
cout << prop << ":" << endl << xmlContent.substr(start, end - start) << endl << endl;
} else {
cout << prop << ": Incomplete" << endl << endl;
}
} else {
cout << prop << ": Not present" << endl << endl;
}
}
}
void write(const string& newFilepath = "") {
string path = newFilepath.empty() ? filepath : newFilepath;
ofstream file(path);
if (file.is_open()) {
file << xmlContent;
file.close();
}
}
// Example method to modify (append a dummy tag to DocumentProperties)
void modifyExample() {
size_t pos = xmlContent.find("</DocumentProperties>");
if (pos != string::npos) {
string insert = "<CustomProperty>Modified Value</CustomProperty>";
xmlContent.insert(pos, insert);
}
}
};
// Usage example:
// int main() {
// VDXHandler handler("sample.vdx");
// if (handler.read()) {
// handler.printProperties();
// handler.modifyExample();
// handler.write("modified.vdx");
// } else {
// cout << "Failed to read file" << endl;
// }
// return 0;
// }
This C++ class reads the .VDX file as a string, prints approximate property sections by string search (for demonstration), modifies by string insertion (as an example), and writes the content back to a file. For production use, integrate an XML library for robust parsing.