Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.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 使用两个XSD字符串进行XML字符串验证(包含)/LSResourceResolver如何工作?_Java_String_Xsd_Include - Fatal编程技术网

Java 使用两个XSD字符串进行XML字符串验证(包含)/LSResourceResolver如何工作?

Java 使用两个XSD字符串进行XML字符串验证(包含)/LSResourceResolver如何工作?,java,string,xsd,include,Java,String,Xsd,Include,我试图根据包含XSD的两个字符串验证XML字符串。一个XSD包括另一个XSD。我得到一个错误: 无法将名称“ServiceSpecificationSchema:ServiceIdentifier”解析为“类型定义”组件 看起来,我的代码无法识别第二个XSD文件。其他人通过使用LSResourceResolver解决了该问题,如下所示: 但在这个例子中,文件存储在本地。有没有一个好的方法可以让这个方法与我的XSD字符串一起工作 任何暗示都将不胜感激 到目前为止,我的代码是: 最后我找到了解决办法

我试图根据包含XSD的两个字符串验证XML字符串。一个XSD包括另一个XSD。我得到一个错误: 无法将名称“ServiceSpecificationSchema:ServiceIdentifier”解析为“类型定义”组件

看起来,我的代码无法识别第二个XSD文件。其他人通过使用LSResourceResolver解决了该问题,如下所示:

但在这个例子中,文件存储在本地。有没有一个好的方法可以让这个方法与我的XSD字符串一起工作

任何暗示都将不胜感激

到目前为止,我的代码是:


最后我找到了解决办法

这对我很有用:

@Service
public class ResourceResolverImpl implements LSResourceResolver {
private ILoadFromSRService iLoadFromSRService;

@Autowired
public ResourceResolverImpl(ILoadFromSRService iLoadFromSRService){
    this.iLoadFromSRService = iLoadFromSRService;
}

public LSInput resolveResource(String type,
                               String namespaceURI,
                               String publicId,
                               String systemId,
                               String baseURI) {
    String string =iLoadFromSRService.getServiceBaseTypeSchema();
    string = string.replace("\n", "").replace("\t", "");
    InputStream resourceAsStream = new ByteArrayInputStream( string.getBytes());
    return new LSInputImpl(publicId, systemId, resourceAsStream);
    }
}

你能分享完成的例子吗?
@Service
public class ResourceResolverImpl implements LSResourceResolver {
private ILoadFromSRService iLoadFromSRService;

@Autowired
public ResourceResolverImpl(ILoadFromSRService iLoadFromSRService){
    this.iLoadFromSRService = iLoadFromSRService;
}

public LSInput resolveResource(String type,
                               String namespaceURI,
                               String publicId,
                               String systemId,
                               String baseURI) {
    String string =iLoadFromSRService.getServiceBaseTypeSchema();
    string = string.replace("\n", "").replace("\t", "");
    InputStream resourceAsStream = new ByteArrayInputStream( string.getBytes());
    return new LSInputImpl(publicId, systemId, resourceAsStream);
    }
}