Webサービスから取得したWSDLファイル内に<wsdl:types></wsdl:types>
のネストされたXSDに対して検証する必要があるXMLファイルがあります。wsdl:types内でネストされたスキーマに対するXMLドキュメントの検証
<wsdl:types></wsdl:types>
の中には、いくつかのものがあります。<xs:schema>
です。
Element '{http://schemas.xmlsoap.org/soap/envelope/}Envelope': No
matching global declaration available for the validation root.
これまでのところ、私は<xs:schema>
秒(すべてを抽出している:私は、XMLファイルを読み込むと、私はプログラムを実行したときのXSDは、しかし、私は次のエラーを取得していたと照合して検証するためにルビーの宝石nokogiri
を使用していますそれらのうち4つ)をコピーし、schema.xsd
ファイルにコピーしました。
コード:
require 'rubygems'
require 'nokogiri'
def validate(document_path, schema_path)
schema = Nokogiri::XML::Schema(File.read(schema_path))
document = Nokogiri::XML(File.read(document_path))
schema.validate(document)
end
validate('data.xml', 'schema.xsd').each do |error|
puts error.message
end
そこで、基本的に私schema.xsd
は、私は自分自身にとは考えていないされ、そこに複数の<xs:schema>
秒を持っている私はschema
をインスタンス化するときnokogiri
がエラーをスローしていなかったため、問題ですオブジェクト。
schema.xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/">
<xs:element name="anyType" nillable="true" type="xs:anyType"/>
<xs:element name="anyURI" nillable="true" type="xs:anyURI"/>
<!-- data in here -->
</xs:schema>
<!-- three more xs:schema tags removed for brevity -->
data.xmlに
<?xml version='1.0' ?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header />
<env:Body>
<CreatePerson xmlns="https://person.example.com/">
<oMessageType xmlns:epa="http://schemas.datacontract.org/2004/07/whatever" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:array="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<person:bodyField>
<!-- data in here -->
</person:bodyField>
<!-- more data in here -->
</oMessageType>
</CreatePerson>
</env:Body>
</env:Envelope>
私は先に行って、あなたがここに持っているかのように私のコードをリファクタリングし、私はまだ同じエラーメッセージました:https://pastebin.com/4Kutuqdh – hyde
@hyde主なアイデアは、埋め込まれたスキーマ要素を検索し、新しい文書を作成したら、新しい文書に対してxsdを作成することができます。それでおしまい。私のサンプルコードは作業コピーですが、プロジェクトの提案では、このコードは美しいものではありません。テストのために、wsdl文字列をコピーして 'str'を置き換えることができます。 –
これが、あなたのコードが行うことです - WSDLからスキーマを抽出します。ただし、抽出されたスキーマを使用してデータを検証しようとすると、同じエラーが発生します。要素 '{http://schemas.xmlsoap.org/soap/envelope/}Envelope':いいえ 検証ルート。 – hyde