Rest-Assured XSD 引用 其他 XSD [英] Rest-Assured XSD References Other XSDs

查看:59
本文介绍了Rest-Assured XSD 引用 其他 XSD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Rest-Assured 根据模式对 XML 验证器进行编程.但是,我无法处理引用其他 XSD 的 XSD,因为我使用 GET 从 URL 检索原始 XSD.

I am programming an XML validator according to schemas using Rest-Assured. However, I am having trouble handling XSDs that reference other XSDs, because I retrieve the original XSD from a URL using GET.

我一直在尝试实现我自己的解析以将 XSD(Strings) 合并为一个 XSD(String),但它正在成为一个递归怪物,并且效率极低/困难.要查看算法,请看帖子末尾.

I have been trying to implement my own parsing to consolidate the XSDs(Strings) into one XSD(String), but it is becoming a recursive monster, and extremely inefficient/difficult. To see the algorithm, look at the end of the post.

我有两个问题:1) 我的问题是我使用 GET 来检索 XSD,所以它不在命名空间内.有没有办法获取所有引用的 XSD 并使用 Rest-Assured 合并它们?我不知道该怎么做.

I have two questions: 1) My problem is that I am using GET to retrieve the XSD, so it's not within the namespace. Is there a way to GET all referenced XSDs and consolidate them using Rest-Assured? I wouldn't have a clue about how to go about this.

2) 一般有没有更好的方法来处理包含?如您所见,我的算法非常昂贵且过于复杂(尤其是 ref 属性),而且我确信如果我更改测试用例,某些东西会很容易出错.

2) Is there a better way to handle includes in general? As you can see, my algorithm is very costly and overcomplicated (especially the ref attribute), and I'm sure something will break easily if I change my test cases.

到目前为止,我的算法(避免复杂性的伪代码)如下所示:

My algorithm(Pseudo-Code to avoid complexity) so far is like the following:

boolean xmlValid(String xmlAddress, String xsdAddress){

    LinkedList XSDList = new LinkedList;
    XSDList.add(xsdAddress);
    xsdString = getExternalXSDStrings(XSDList);

    try{ //No PseudoCode here
       RestAssured.expect().
            statusCode(200).
            body(
                    RestAssuredMatchers.matchesXsd(xsdString)).
            when().
            get(xmlAddress);
    }catch Exceptions{...}
}

String getExternalXSDStrings(LinkedList xsdReferences, String prevString){
    LinkedList recursiveXSDReferences = new LinkedList();

    for(xsdRef:xsdReferences){
         xsdAddress = "http://..." + xsdRef;
         Open InputStream From URL;
         while(inputLine != null){

             if(prologFlag) //Do Nothing, this is to avoid multiple prologs ;

             else if(includeFlag){

                 if(refFlag) Note Reference;
                 else recursiveXSDReferences.add(includeReference);

             }else if(refFlag){

                 referenceDefinition = Extract Reference Element Definition;
                 xsdString = xsdString + referenceDefinition;

             }else{
                 xsdString = xsdString + inputLine;
             }
         }
         Close input stream;
    }
    xsdString = prevString + xsdString;
    if(xsdReferences.length > 0) return getExternalXSDStrings(recursiveXSDReferences , xsdString);
    else return xsdString;
}

在此先非常感谢您!

推荐答案

也许可以在详细配置中使用 XmlConfig.这使您可以访问配置功能和命名空间等.例如,如果您想禁用外部 DTD 的加载,您可以这样做:

Perhaps can make use of the XmlConfig in detailed configuration. This gives you access to configure features and namespaces etc. For example if you want to disable the loading of external DTD's you could do:

given().config(RestAssured.config().xmlConfig(xmlConfig().disableLoadingOfExternalDtd())). .. 

所以也许您可以查看disableLoadingOfExternalDtd"方法以了解它是如何实现的以获取一些提示.

So perhaps you could look in the "disableLoadingOfExternalDtd" method to see how it's implemented to get some hints.

这篇关于Rest-Assured XSD 引用 其他 XSD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆