从mysql数据库解析XML文件时出错

时间:2022-12-01 11:14:36

i am working with jsp server,mysql database and xsl transformations. I have a link from an xml file stored to my pc so as to translate it with xslt.If i do this and everything is fine:

我正在使用jsp服务器,mysql数据库和xsl转换。我有一个从存储到我的电脑的xml文件的链接,以便用xslt翻译它。如果我这样做,一切都很好:

String url="c:\\xampp\\tomcat\\webapps\\examples\\sakias.xml";
Document doc = builder.parse(new File(url)); and so on as usual...

The problem is that if i store the url link (c:\\xampp\\tomcat\\webapps\\examples\\sakias.xml) in a column to mysql database and then fetch it i get the following error:

问题是,如果我将一个列中的url链接(c:\\ xampp \\ tomcat \\ webapps \\ examples \\ sakias.xml)存储到mysql数据库然后获取它,我会收到以下错误:

org.xml.sax.SAXParseException; systemId: file:///c:/xampp/; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog

Is there a problem with encoding;escape characters; It is really weird.

编码是否存在问题;转义字符;这真的很奇怪。

PS1:Is there an another solution to store xml directly into sql database;My version does not support xml field.Can i store it escaped as String;

PS1:是否有另一种解决方案将xml直接存储到sql数据库中;我的版本不支持xml字段。可以将它存储为字符串转义;

PS2: I changed the url link to this form(http://localhost:8080/examples/jsp/jsp2/loginrecord/link_error.xml) but still the same error. I print it and it is fine but still the same error

PS2:我将url链接更改为此表单(http:// localhost:8080 / examples / jsp / jsp2 / loginrecord / link_error.xml)但仍然出现相同的错误。我打印它,它很好,但仍然是同样的错误

1 个解决方案

#1


0  

Your URL in the database should not have the \ escaped. It should look like c:\xampp\tomcat\webapps\examples\sakias.xml

您在数据库中的URL不应具有\转义。它应该看起来像c:\ xampp \ tomcat \ webapps \ examples \ sakias.xml

Also, yes, you can store XML in SQL database. You shouldn't have to worry about escaping it for storage (you may need to escape it if you're constructing the string in Java), but you should worry about column sizes. You might choose to store it as TEXT instead of VARCHAR (there's no such thing as String SQL type).

此外,是的,您可以将XML存储在SQL数据库中。您不必担心将其转储以进行存储(如果您在Java中构造字符串,则可能需要将其转义),但您应该担心列大小。您可以选择将其存储为TEXT而不是VARCHAR(不存在String SQL类型)。

#1


0  

Your URL in the database should not have the \ escaped. It should look like c:\xampp\tomcat\webapps\examples\sakias.xml

您在数据库中的URL不应具有\转义。它应该看起来像c:\ xampp \ tomcat \ webapps \ examples \ sakias.xml

Also, yes, you can store XML in SQL database. You shouldn't have to worry about escaping it for storage (you may need to escape it if you're constructing the string in Java), but you should worry about column sizes. You might choose to store it as TEXT instead of VARCHAR (there's no such thing as String SQL type).

此外,是的,您可以将XML存储在SQL数据库中。您不必担心将其转储以进行存储(如果您在Java中构造字符串,则可能需要将其转义),但您应该担心列大小。您可以选择将其存储为TEXT而不是VARCHAR(不存在String SQL类型)。