当前位置: 首页 > 知识库问答 >
问题:

使用xsd文件验证Soap xml响应

邵骁
2023-03-14

使用https://www.freeformatter.com/xml-validator-xsd.html

如果我将soapenf完全从这里的响应和模式的混合中去掉,它工作得很好,但我希望两者都能做到。

(仅供参考,我想指出这个wsdl和xsd没有在endpoint上公开,CISCO提供了wsdl和xsd文件的zip文件)然后您可以根据wsdl/xsd向服务器发送请求,它会工作。但是wsdl和xsd在您安装服务的cisco.com或vm或域上不可用)

如果我指向文件,这在c#中可以完美工作,但我想将xml文档加载到NSXMLDocument变量文档中,并让它指向自己的模式文件,然后只需调用验证

我有以下soap xml

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
<soapenv:Body>
<ns:getCCMVersionResponse xmlns:ns="http://www.cisco.com/AXL/API/10.5"><return><componentVersion>     
<version>10.5.2.11900(3)</version>
</componentVersion>
</return>
</ns:getCCMVersionResponse>
</soapenv:Body>
</soapenv:Envelope>

我从cisco提供的xsd文件中提取了最基本的内容,该在线工具可以与

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:axlapi="http://www.cisco.com/AXL/API/10.5" 
attributeFormDefault="unqualified" elementFormDefault="unqualified" 
targetNamespace="http://www.cisco.com/AXL/API/10.5" version="10.5">
 <xsd:import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/>
  <xsd:complexType name="GetCCMVersionRes">
    <xsd:complexContent>
        <xsd:extension base="axlapi:APIResponse">
            <xsd:sequence>
                <xsd:element name="return">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="componentVersion">
                                <xsd:complexType>
                                    <xsd:sequence>
                                        <xsd:element name="version" type="axlapi:String50"/>
                                    </xsd:sequence>
                                </xsd:complexType>
                            </xsd:element>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:extension>
    </xsd:complexContent>
</xsd:complexType>
<xsd:element name="getCCMVersionResponse" type="axlapi:GetCCMVersionRes"/>
    <xsd:simpleType name="String50">
    <xsd:restriction base="xsd:string">
        <xsd:maxLength value="50"/>
    </xsd:restriction>
</xsd:simpleType>
<xsd:complexType abstract="true" name="APIResponse">
    <xsd:annotation>
        <xsd:documentation>All responses must extend abstractResponse.</xsd:documentation>
    </xsd:annotation>
    <xsd:attribute name="sequence" type="xsd:unsignedLong" use="optional"/>
</xsd:complexType>
</xsd:schema>

请注意,我必须将以下内容添加到xsd文件中,以使其通过SOAP错误

<xsd:import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/>

它在在线工具中工作

现在这是一个很棒的在线工具,但我想验证一下文档本身。这是通过在Soap请求信封元素中添加“noNamespaceSchemaLocation”或“schemaLocation”以及指向xsd文件(或我在上面创建的部分文件)的http路径来实现的(如果您阅读了联机工具)

它目前托管在http://test123a.epizy.com/getCCMVersion.xsd(我希望它不是因为它是一个免费的主机,我有一个问题),但也应该有方法来完成这个使用文件:///

我使用的是macOS和objective-c,但所有的代码都在操作soap xml响应头,并将file:///.我也尝试过http://。

有人能解开这个绝对的谜团吗?从网上的一些例子来看,这似乎很简单......

使用Cocoa中的xsd文件验证XML架构?

http://answerqueen.com/2j/q7vz0zv32j

如何修复soapenv:XSD模式中的信封问题,同时使用SOAP请求/响应进行验证

https://code.i-harness.com/en/q/8bfd7

如何正确引用本地XML Schema文件?

Cvc elt。1: 找不到元素“soap:Envelope”的声明

提前谢谢你的帮助

这家伙从来没有得到答案SOAP响应模式验证

共有1个答案

空正豪
2023-03-14

事实证明,您只能验证其中一个。您不能在一次调用中加载soap响应并验证soap以及其中的xml。您可以分离soap和xml,并分别验证。

下面是执行此操作的正确代码

<?xml version='1.0' encoding='UTF-8'?>"
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:getCCMVersionResponse xmlns:ns="http://www.cisco.com/AXL/API/10.5"                                                       
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                                              
xsi:schemaLocation="http://www.cisco.com/AXL/API/10.5  
/Users/michael/Downloads/axlsqltoolkit/schema/current/getCCMVersion.xsd">
<return>
<componentVersion>
<version>10.5.2.11900(3)</version>
</componentVersion>
</return>
</ns:getCCMVersionResponse>
</soapenv:Body>

您不能同时验证SOAP和内部的XML。您必须使用xpath才能访问xml并且可以验证,因为验证肥皂并不重要。

有趣的是xml

我无法使用xsi:noNameSpaceSchemaLocation=”file:///Users/michael/Downloads/axlsqltoolkit/schema/current/getCCMVersion.xsd“”

如xml xsi中所示:schemaLocation=”http://www.cisco.com/AXL/API/10.5
/Users/michael/Downloads/axlsqltoolkit/schema/current/getCCMVersion。xsd“

所以替代方案必须在上面使用。

此外,我还必须根据xml响应xmlns编辑模式文件以修复一些命名空间问题:ns=”http://www.cisco.com/AXL/API/10.5,ns是命名空间,

但在模式文件中,它引用为axlapi,所有引用都更改为ns

希望这将在未来帮助某人。仅供参考,指向整个AXLSoap.xsd文件进行验证需要几分钟,不得不放弃

事实证明,您只能验证其中一个。您不能在一次调用中加载soap响应并验证soap以及其中的xml。您可以分离soap和xml,并分别验证。

下面是执行此操作的正确代码

<?xml version='1.0' encoding='UTF-8'?>"
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:getCCMVersionResponse xmlns:ns="http://www.cisco.com/AXL/API/10.5"                                                       
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                                              
xsi:schemaLocation="http://www.cisco.com/AXL/API/10.5  
/Users/michael/Downloads/axlsqltoolkit/schema/current/getCCMVersion.xsd">
<return>
<componentVersion>
<version>10.5.2.11900(3)</version>
</componentVersion>
</return>
</ns:getCCMVersionResponse>
</soapenv:Body>

您不能同时验证SOAP和内部的XML。您必须使用xpath才能访问xml并且可以验证,因为验证肥皂并不重要。

有趣的是xml

我无法使用xsi:noNameSpaceSchemaLocation=”file:///Users/michael/Downloads/axlsqltoolkit/schema/current/getCCMVersion.xsd“”

如xml xsi中所示:schemaLocation=”http://www.cisco.com/AXL/API/10.5
/Users/michael/Downloads/axlsqltoolkit/schema/current/getCCMVersion。xsd“

所以替代方案必须在上面使用。

此外,我还必须根据xml响应xmlns编辑模式文件以修复一些命名空间问题:ns=”http://www.cisco.com/AXL/API/10.5,ns是命名空间,

但在模式文件中,它引用为axlapi,所有引用都更改为ns

希望这将在未来帮助某人。仅供参考,指向整个AXLSoap.xsd文件进行验证需要几分钟,不得不放弃

这里是最后一个Objective-c NSXMLDocument函数,用于处理验证肥皂或xml。

    BOOL validateDocumentUsingXMLSchemaAtPath( NSXMLDocument *doc, 
NSString* xsdPath, NSString *schemaNameSpace )
{
    BOOL validationResult = NO;  // Default to failing validation.

    // Get the root of the document.
    NSXMLElement *rootElement = [doc rootElement];

    // Add the XMLSchema-instance namespace, if it doesn't already exist
    NSXMLNode *namespace = [NSXMLNode namespaceWithName:@"xsi"
                                        stringValue:@"http://www.w3.org/2001/XMLSchema-instance"];
    [rootElement addNamespace:namespace];

    // Add the No Namespace Schema Location attribute referencing the local XSD file, and associate the XML Schema for validation.
    NSURL *xsdURL = [NSURL fileURLWithPath:xsdPath];

    NSString *schemaLocation = nil;
    if ( namespace == nil )
    {
        schemaLocation = @"noNamespaceSchemaLocation";
        schemaNameSpace = @"";
    }
    else
    {
        schemaLocation = @"schemaLocation";
    }

    NSString *schemaSpace = [NSString stringWithFormat:@"%@%@%@", schemaNameSpace, ([schemaNameSpace length] > 0) ? @" " : @"", [xsdURL description]];

NSXMLNode *schemaAttribute = [NSXMLNode attributeWithName:[NSString stringWithFormat:@"xsi:%@", schemaLocation]
                                                    stringValue:schemaSpace];
    [rootElement addAttribute:schemaAttribute];

    // Validate the document
    NSError *error = nil;
    validationResult = [doc validateAndReturnError:&error];

    if ( !validationResult )
         NSLog( @" %@", [error localizedDescription] );

    return validationResult;
    }


//usage
//find your soap, or xml document and put it in xmlDoc
               BOOL ret = validateDocumentUsingXMLSchemaAtPath(xmlDoc,xsdURL, @"http://www.cisco.com/AXL/API/10.5");
 类似资料:
  • 对于任何熟悉xml模式的人来说,这可能是一个基本错误,它可能只是Eclipse Indigo中的一个小的配置更改,但它耗尽了我的google搜索能力,所有实验都未能解决它。 它是现有项目中的一个xsd文件,运行良好。我将该项目设置为Eclipse中的maven/dynamic web项目,在为dynamic web Project2.4打开Eclipse的project facet之后,Eclip

  • 我正在使用Delphi10.2更新3。我按照这些说明验证生成的xml文档。 属性noNamespaceSchema位置对XML解析有什么影响? 使用Windows DOM和TXMLDocument验证XML:在某些计算机上不起作用 delphi中msxml的模式验证 但我有一个错误。“DTD/架构中未定义元素‘jegyzek\u adatok’上的属性‘noNamespaceSchemaLocat

  • 谁能解释一下如何使用notepad++根据XSD验证xml文件。“XML Tools”插件下拉列表中没有提供指定XSD文件的选项。在plugins子目录中正确安装XML插件,并将3个DLL复制到notepad++EXE子目录。其他XML“验证”特性也可以工作,但无法针对XSD进行验证。

  • 我在xsd中有一个问题,我不知道为什么stackoverflow阻止我问。我想有一个看起来像这样的标签 但我还想使用验证来验证这一点。 在xsd中,我有 我可以单独通过语法测试,但当我将验证和xml文件放在一起时,我不断收到错误,说order属性不允许出现在这个标记中。我想使用这个order属性,因为它是必需的。如果有人能告诉我怎么做!非常感谢!

  • 问题内容: 我正在使用来验证XML文件。我已经完成了一个仅使用导入的架构,并且一切正常。现在,我尝试使用另一种使用导入和包含的模式进行验证。我的问题是主模式中的元素被忽略,验证表明无法找到它们的声明。 这是我构建模式的方法: 现在这是main.xsd中声明的摘录 如果我将包含的XSD的代码复制到main.xsd中,则可以正常工作。如果我不这样做,验证将找不到“元素”的声明。 问题答案: 您需要使用

  • 我在验证xml和xsd时遇到问题。我从xsd模式中得到这个错误。 src解决方案。4.2:解析组件“urn:id”时出错。检测到“urn:id”位于命名空间“urn:schemas microsoft com:xml-diffgram-v1”中,但此命名空间中的组件无法从架构文档中引用virtual://server/schema.xsd。如果名称空间不正确,可能需要更改“urn:id”的前缀。如