How do I open a JSON file in Saxon 10.1?

非 Y 不嫁゛ 提交于 2021-02-11 12:28:43

问题


Following the instructions in the Saxonica documentation I have code that works great for opening an XML file.

But when I use that same code to open a JSON file I get:

Caused by: net.sf.saxon.s9api.SaxonApiException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
    at net.sf.saxon.s9api.DocumentBuilder.build(DocumentBuilder.java:360)
    at net.windward.datasource.xml.SaxonDataSource.ctor(SaxonDataSource.java:231)
    at net.windward.datasource.xml.SaxonDataSource.<init>(SaxonDataSource.java:154)
    ... 2 more
Caused by: net.sf.saxon.trans.XPathException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
    at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:459)
    at net.sf.saxon.event.Sender.send(Sender.java:142)
    at net.sf.saxon.Configuration.buildDocumentTree(Configuration.java:4184)
    at net.sf.saxon.s9api.DocumentBuilder.build(DocumentBuilder.java:357)
    ... 4 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
    at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1472)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:994)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:841)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:770)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
    at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:439)
    ... 7 more

What do I need to do differently?


回答1:


You haven't told us what you're doing, so it's hard to say what you should do differently. But clearly you're supplying a JSON file to an interface that expects XML.

The simplest way to load json is using the json-doc() function,.



来源:https://stackoverflow.com/questions/62956935/how-do-i-open-a-json-file-in-saxon-10-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!