Java new project 注意事项
新建一个java项目的时候,要注意2个地方
- Java Compiler : Jdk 要正确
- Java Build Path -> Libraries : 引入jar包
import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import org.jdom2.JDOMException; import com.marklogic.xcc.ContentSource; import com.marklogic.xcc.ContentSourceFactory; import com.marklogic.xcc.Request; import com.marklogic.xcc.ResultSequence; import com.marklogic.xcc.Session; import com.marklogic.xcc.exceptions.RequestException; import com.marklogic.xcc.exceptions.XccConfigException; public class XQuery { public static void main(String[] args) throws URISyntaxException, XccConfigException, RequestException, JDOMException, IOException { URI uri = new URI("xcc://yuxi:pacific@192.168.11.128:8019/lein_database"); ContentSource contentSource = ContentSourceFactory.newContentSource (uri); Session session = contentSource.newSession(); String xql = "xquery version \"1.0-ml\";"; xql += "declare namespace ss = \"urn:schemas-microsoft-com:office:spreadsheet\";"; xql += "doc(\"/opt/MarkLogic/lein_root/partner_creatives-1.xml\")/ss:Workbook/ss:Styles/ss:Style[@ss:ID=\"s27\"];"; Request request = session.newAdhocQuery (xql); ResultSequence rs = session.submitRequest (request); System.out.println (rs.asString()); System.out.println(""); StringReader reader = new StringReader(rs.asString()); InputSource source = new InputSource(reader); SAXBuilder sb = new SAXBuilder(); Document doc = sb.build(source); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); String output = outputter.outputString(doc); System.out.println (output); session.close(); } }