Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何解析实体声明并获取XML中的文件路径?_Java_Xml_Jaxp_Entityresolver - Fatal编程技术网

Java 如何解析实体声明并获取XML中的文件路径?

Java 如何解析实体声明并获取XML中的文件路径?,java,xml,jaxp,entityresolver,Java,Xml,Jaxp,Entityresolver,但它给我abcd,但我需要文件路径'sunset.jpg' 我也试过 document.getDoctype().getEntities().item(i).getNodeName(), 但是我认为我在返回类型上有一些问题,因为我希望图像文件被读取为字节数组,?退货类型应该是什么?给您: builder.setEntityResolver(new EntityResolver() { @Override public InputSourc

但它给我abcd,但我需要文件路径'sunset.jpg'

我也试过

 document.getDoctype().getEntities().item(i).getNodeName(),  
但是我认为我在返回类型上有一些问题,因为我希望图像文件被读取为字节数组,?退货类型应该是什么?

给您:

builder.setEntityResolver(new EntityResolver() {

            @Override
            public InputSource resolveEntity(String publicId, String systemId)
                    throws SAXException, IOException {
                // TODO Auto-generated method stub

                System.out.println("Public and System IDs"+publicId+"  "+systemId);
                return new InputSource(new StringReader(referDM));
            }
        });
啊!!工作起来很有魅力:)我之前试过这么做,但完全忘了打字!谢谢你的快速解决方案。
builder.setEntityResolver(new EntityResolver() {

            @Override
            public InputSource resolveEntity(String publicId, String systemId)
                    throws SAXException, IOException {
                // TODO Auto-generated method stub

                System.out.println("Public and System IDs"+publicId+"  "+systemId);
                return new InputSource(new StringReader(referDM));
            }
        });
Entity entity = (Entity) document.getDoctype().getEntities().item(i);
String path = entity.getSystemId();