【问题标题】:Read XML file in S3 using SAXParser使用 SAXParser 在 S3 中读取 XML 文件
【发布时间】:2016-08-31 12:52:43
【问题描述】:

我需要使用 SAXParser 读取位于 S3 中的 xml 文件。我找到了很多关于如何在 S3 中读取法线的示例,但没有任何与我的问题相关的材料。

我使用 SAXParser 的原因是因为我需要验证 XML 文件。以下是验证本地 xml 文件的代码示例。

Source schemaFile = new StreamSource(entitiesScriptSchema);
System.out.println(path);
Source xmlFile = new StreamSource(new File(path));
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemaFile);
Validator validator = schema.newValidator();
validator.validate(xmlFile);

【问题讨论】:

    标签: java xml amazon-s3 aws-sdk saxparser


    【解决方案1】:

    您将通过以下方式获得 S3 对象的 InputStream:

    InputStream s3stream = s3Client.getObject("bucket", "key").getObjectContent();

    那么您应该能够像任何其他 Java InputStream 一样将 InputStream 传递给 SAX 解析器。

    【讨论】:

    • 你的意思是把输入流放在这里? Source xmlFile = new StreamSource(new File(path));
    • 是的,将该行更改为Source xmlFile = new StreamSource(s3stream);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-20
    • 1970-01-01
    • 1970-01-01
    • 2017-06-27
    • 1970-01-01
    相关资源
    最近更新 更多