String filePath = "E:/桌面/cesgi.vsdx";
File file = new File(filePath);
XmlVisiodocument xmlVisiodocument = new XmlVisiodocument(new FileInputStream(file));
Collection pages = xmlVisiodocument.getPages();
Iterator iterator = pages.iterator();
//存储所有连线起点的集合
List startLine = new ArrayList<>();
//存储所有连线起点的集合
List endLine = new ArrayList<>();
//存储所有形状id和文字的集合
HashMap idAndName = new HashMap<>();
//存储所有形状id和样式的集合
HashMap idAndStyle = new HashMap<>();
//存储所有形状id和宽高的集合
HashMap idAndSize = new HashMap<>();
while (iterator.hasNext()) {
XDGFPage xdgfPage = iterator.next();
XDGFPageContents content = xdgfPage.getContent();
//所有包含文字的形状节点
Collection shapes = content.getShapes();
Iterator iterator1 = shapes.iterator();
while (iterator1.hasNext()) {
XDGFShape xdgfShape = iterator1.next();
if (xdgfShape.hasText() && !xdgfShape.getText().getTextContent().equals("")) {
//存储文字
idAndName.put(Long.toString(xdgfShape.getID()), xdgfShape.getTextAsString());
//存储形状类型
idAndStyle.put(Long.toString(xdgfShape.getID()), xdgfShape.getName());
//存储形状数据,xml结构中*100为业务需要
idAndSize.put(Long.toString(xdgfShape.getID()), " ");
}
可以实现对vsdx文件的实时读取,解析,将数据转化为自定义xml



