使用 Apache POI XDGF 读取 vsdx 文件

引入依赖


    org.apache.logging.log4j
    log4j-core
    2.22.1


    org.apache.logging.log4j
    log4j-slf4j-impl
    2.22.1


    org.apache.logging.log4j
    log4j-1.2-api
    2.22.1


    org.apache.logging.log4j
    log4j-api
    2.22.1



    org.apache.poi
    poi
    5.2.5



    org.apache.poi
    poi-ooxml
    5.2.5



    commons-io
    commons-io
    2.15.1

下载示例文件:A flowchart diagram that details the steps for buying a property

Java代码如下:

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.poi.xdgf.extractor.XDGFVisioExtractor;
import org.apache.poi.xdgf.usermodel.XmlVisioDocument;
import org.w3c.dom.Node;

public class VsdxReadTest {

	public static void main(final String[] args) throws FileNotFoundException, IOException {
		final XmlVisioDocument xvd = new XmlVisioDocument(new FileInputStream("data\\vsdx\\tf16403429.vsdx"));
		// open VSD file
		final XDGFVisioExtractor extractor = new XDGFVisioExtractor(xvd);
		System.out.println("------text-----");
		System.out.println(extractor.getText());
		System.out.println("------text-----");

		extractor.getDocument().getPages().forEach(p -> {
			final StringBuilder bud = new StringBuilder();
			System.out.println("页名:" + p.getName());

			p.getContent().getXmlObject().getShapes().getShapeList().forEach(s -> {
				System.out.println("------xml-----" + s.getID() + "---" + s.getName());
				System.out.println(s);
				System.out.println("------xml-----" + s.getID() + "---" + s.getName());

				for (int i = 0; i < s.getDomNode().getChildNodes().getLength(); i++) {
					final Node n = s.getDomNode().getChildNodes().item(i);
					printNode(bud, n, 1);

					if (n.getChildNodes().getLength() > 0) {
						Boolean print2 = Boolean.FALSE;
						for (int j = 0; j < n.getChildNodes().getLength(); j++) {
							final Node n2 = n.getChildNodes().item(j);
							if (printNode(bud, n2, 2)) {
								print2 = Boolean.TRUE;
							}

							if (n2.getChildNodes().getLength() > 0) {
								Boolean print3 = Boolean.FALSE;
								for (int k = 0; k < n2.getChildNodes().getLength(); k++) {
									final Node n3 = n2.getChildNodes().item(k);
									if (printNode(bud, n3, 3)) {
										print3 = Boolean.TRUE;
									}
								}
								if (print3) {
									bud.append(System.lineSeparator());
								}
							}
						}
						if (print2) {
							bud.append(System.lineSeparator());
						}
					}
				}

			});

			System.out.println("------text-----");
			System.out.println(bud.toString());
			System.out.println("------text-----");
		});

	}

	private static Boolean printNode(final StringBuilder bud, final Node node, final int level) {
		if (node.getNodeName().contains("#text")) {
			bud.append(node.getNodeValue());
			return Boolean.TRUE;
		}
		return Boolean.FALSE;
	}

}

输出结果如下

------text-----
​Property buying Flowchart
Start with an agent 
you trust
Consult with agent to determine your property wants and needs
Review and complete paperwork
Go to preferred lender,
get pre-qualified and
pre-approval for loan amount
With agent, analyze
market to choose properties of interest
View properties
with agent
​A
​A
Select ideal property
and write offer to
purchase
Negotiate
& Counteroffer: Agreement?
Accept the contract
Secure underwriting,
obtain loan approval
Select/Contact closing attorney for title exam
and title insurance
Schedule inspection
and survey
Close on the
property
Yes
No

------text-----
页名:Page-1
------xml-----188---null

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
      
    
  
  
    
      
      
      
      
    
  
  
    
    
    
    
    
    
      
      
    
    
      
      
    
    
      
      
    
    
      
      
    
    
      
      
    
  
  
    
    ​Property buying Flowchart
  

------xml-----188---null
------xml-----239---Start/End.132

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
    
    
      
    
  
  
    
      
      
    
  
  
    
      
      
      
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
    
      
      
    
  
  
    
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
    
    
      
      
      
      
    
    
      
      
    
    
      
      
    
  
  
    
    
    
    Start with an agent
    
    
    you trust
  

------xml-----239---Start/End.132
------xml-----256---null

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
      
      
      
    
  
  
    
      
      
    
  
  
    
      
    
    
      
      
    
    
  

------xml-----256---null
------xml-----257---Process.133

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
    
    
      
    
  
  
    
      
      
    
  
  
    
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
    
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
  
  
    
    Consult with agent to determine your property wants and needs
  

------xml-----257---Process.133
------xml-----258---null

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
      
      
      
    
  
  
    
      
      
    
  
  
    
      
    
    
      
      
    
    
      
      
    
    
      
      
    
  

------xml-----258---null
------xml-----259---Process.135

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
    
    
      
    
  
  
    
      
      
    
  
  
    
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
    
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
  
  
    
    Review and complete paperwork
  

------xml-----259---Process.135
------xml-----260---null

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
      
      
      
    
  
  
    
      
      
    
  
  
    
      
    
    
      
      
    
    
      
      
    
    
      
      
    
  

------xml-----260---null
------xml-----261---Process.137

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
    
    
      
    
  
  
    
      
      
    
  
  
    
      
      
      
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
    
      
      
    
  
  
    
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
  
  
    
    
    
    Go to preferred lender,
    
    
    get pre-qualified 
    
    and
    
    
    pre-approval for loan amount
  

------xml-----261---Process.137
------xml-----262---null

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
      
      
      
    
  
  
    
      
      
    
  
  
    
      
    
    
      
      
    
    
  

------xml-----262---null
------xml-----263---Process.157

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
    
    
      
    
  
  
    
      
      
    
  
  
    
      
      
      
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
    
      
      
    
  
  
    
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
  
  
    
    
    
    With agent, analyze
    
    
    market to choose properties of interest
  

------xml-----263---Process.157
------xml-----264---null

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
      
      
      
    
  
  
    
      
      
    
  
  
    
      
    
    
      
      
    
    
  

------xml-----264---null
------xml-----265---Process.164

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
    
    
      
    
  
  
    
      
      
    
  
  
    
      
      
      
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
    
      
      
    
  
  
    
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
  
  
    
    
    
    View properties
    
    
    with agent
  

------xml-----265---Process.164
------xml-----266---null

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
      
      
      
    
  
  
    
      
      
    
  
  
    
      
    
    
      
      
    
    
      
      
    
    
      
      
    
  

------xml-----266---null
------xml-----267---On-page reference.194

  
  
  
  
  
  
  
    
      
      
    
  
  
    
      
      
      
    
  
  
    
    ​A
  

------xml-----267---On-page reference.194
------xml-----268---On-page reference.268

  
  
  
  
  
  
  
    
      
      
    
  
  
    
      
      
      
    
  
  
    
    ​A
  

------xml-----268---On-page reference.268
------xml-----269---null

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
      
      
      
    
  
  
    
      
      
    
  
  
    
      
    
    
      
      
    
    
  

------xml-----269---null
------xml-----270---Process.166

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
    
    
      
    
  
  
    
      
      
    
  
  
    
      
      
      
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
    
      
      
    
  
  
    
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
  
  
    
    
    
    Select ideal property
    
    
    and write offer to
    
    
    purchase
  

------xml-----270---Process.166
------xml-----271---null

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
      
      
      
    
  
  
    
      
      
    
  
  
    
      
    
    
      
      
    
    
      
      
    
    
      
      
    
  

------xml-----271---null
------xml-----272---Decision.170

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
    
    
      
    
  
  
    
      
    
    
      
      
    
  
  
    
      
      
      
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
      
    
    
      
    
  
  
    
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
      
    
    
      
    
    
      
    
  
  
    
    
    
    Negotiate
    
    
    & Counteroffer: Agreement?
  

------xml-----272---Decision.170
------xml-----275---Process.177

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
    
    
      
    
  
  
    
      
      
    
  
  
    
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
    
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
  
  
    
    Accept the contract
  

------xml-----275---Process.177
------xml-----276---null

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
      
      
      
    
  
  
    
      
      
    
  
  
    
      
    
    
      
      
    
    
  

------xml-----276---null
------xml-----277---Process.179

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
    
    
      
    
  
  
    
      
      
    
  
  
    
      
      
      
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
    
      
      
    
  
  
    
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
  
  
    
    
    
    Secure underwriting,
    
    
    obtain loan approval
  

------xml-----277---Process.179
------xml-----278---null

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
      
      
      
    
  
  
    
      
      
    
  
  
    
      
    
    
      
      
    
    
  

------xml-----278---null
------xml-----279---Process.181

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
    
    
      
    
  
  
    
      
      
    
  
  
    
      
      
      
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
    
      
      
    
  
  
    
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
  
  
    
    
    
    Select/Contact closing attorney for title exam
    
    
    and title insurance
  

------xml-----279---Process.181
------xml-----280---null

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
      
      
      
    
  
  
    
      
      
    
  
  
    
      
    
    
      
      
    
    
      
      
    
    
      
      
    
  

------xml-----280---null
------xml-----281---Process.183

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
    
    
      
    
  
  
    
      
      
    
  
  
    
      
      
      
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
    
      
      
    
  
  
    
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
  
  
    
    
    
    Schedule inspection
    
    
    and survey
  

------xml-----281---Process.183
------xml-----283---null

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
      
      
      
    
  
  
    
      
      
    
  
  
    
      
    
    
      
      
    
    
  

------xml-----283---null
------xml-----284---Start/End.185

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
    
    
      
    
  
  
    
      
      
    
  
  
    
      
      
      
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
      
    
    
      
    
    
      
      
    
  
  
    
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    
      
    
    
      
    
    
      
      
      
      
    
    
      
      
    
    
      
      
    
  
  
    
    
    
    Close on the
    
    
    property
  

------xml-----284---Start/End.185
------xml-----289---null

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
      
      
      
      
    
  
  
    
      
      
    
  
  
    
      
    
  
  
    
      
    
    
      
      
    
    
      
      
    
    
      
      
    
  
  
    
    Yes
  

------xml-----289---null
------xml-----291---Dynamic connector

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
      
      
      
      
      
    
  
  
    
      
      
    
  
  
    
      
    
  
  
    
      
      
    
    
      
      
    
    
      
      
    
  
  
    
    No
  

------xml-----291---Dynamic connector
------text-----
​Property buying Flowchart

Start with an agent 
you trust

Consult with agent to determine your property wants and needs

Review and complete paperwork

Go to preferred lender,
get pre-qualified and
pre-approval for loan amount

With agent, analyze
market to choose properties of interest

View properties
with agent

​A

​A

Select ideal property
and write offer to
purchase

Negotiate
& Counteroffer: Agreement?

Accept the contract

Secure underwriting,
obtain loan approval

Select/Contact closing attorney for title exam
and title insurance 

Schedule inspection
and survey

Close on the
property

Yes

No


------text-----

参考资料:

1. Apache POI - HDGF and XDGF - Java API To Access Microsoft Visio Format Files

2.Introduction to the Visio file format (.vsdx)

3.java导入visio文件_xdgfvisiorenderer-CSDN博客

4.Featured Visio templates and diagrams - Microsoft Support

你可能感兴趣的:(apache)