2
我是(或者说,我使用的Net::SAML2
库)试图规范化XML并获取命名空间错误。我有一个印象,这是正确设置前缀列表的问题,但我不知道应该在什么格式。(Net::SAML2
似乎试图生成一个列表,但出现空的。)示例代码:使用XML前缀列表指定嵌套命名空间:: CanonicalizeXML
use XML::CanonicalizeXML;
my $xml = '<saml:Assertion xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="2.0" ID="pfx894bbcab-a4d3-7694-5b56-26dc207e3479" IssueInstant="2014-09-12T01:51:30Z"><saml:Issuer>http://example.com/metadata</saml:Issuer><saml:Subject><saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient">[email protected]</saml:NameID><saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"><saml:SubjectConfirmationData NotOnOrAfter="2014-09-12T01:54:30Z" Recipient="{recipient}" InResponseTo="3e19c9272c04531d0c01643749e9dfda" /></saml:SubjectConfirmation></saml:Subject><saml:Conditions NotBefore="2014-09-12T01:48:30Z" NotOnOrAfter="2014-09-12T01:54:30Z"><saml:AudienceRestriction><saml:Audience>{audience}</saml:Audience></saml:AudienceRestriction></saml:Conditions><saml:AuthnStatement AuthnInstant="2014-09-12T01:51:29Z" SessionNotOnOrAfter="2014-09-13T01:51:30Z" SessionIndex="_59f97890-1bff-0132-6393-782bcb56fcaa"><saml:AuthnContext><saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef></saml:AuthnContext></saml:AuthnStatement><saml:AttributeStatement><saml:Attribute Name="first_name" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"><saml:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Billy</saml:AttributeValue></saml:Attribute></saml:AttributeStatement></saml:Assertion>';
my $xpath = '<XPath>(//. | //@* | //namespace::*)</XPath>';
my $prefixlist = '';
my $canon = XML::CanonicalizeXML::canonicalize($xml,$xpath,$prefixlist,1,0);
产生这些警告:
namespace error : Namespace prefix saml on Assertion is not defined
ID="pfx894bbcab-a4d3-7694-5b56-26dc207e3479" IssueInstant="2014-09-12T01:51:30Z"
^
namespace error : Namespace prefix saml on Issuer is not defined
ab-a4d3-7694-5b56-26dc207e3479" IssueInstant="2014-09-12T01:51:30Z"><saml:Issuer
^
namespace error : Namespace prefix saml on Subject is not defined
2T01:51:30Z"><saml:Issuer>http://example.com/metadata</saml:Issuer><saml:Subject
^
namespace error : Namespace prefix saml on NameID is not defined
ubject><saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient"
^
namespace error : Namespace prefix saml on SubjectConfirmation is not defined
:NameID><saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"
^
namespace error : Namespace prefix saml on SubjectConfirmationData is not defined
54:30Z" Recipient="{recipient}" InResponseTo="3e19c9272c04531d0c01643749e9dfda"
^
namespace error : Namespace prefix saml on Conditions is not defined
:Conditions NotBefore="2014-09-12T01:48:30Z" NotOnOrAfter="2014-09-12T01:54:30Z"
^
namespace error : Namespace prefix saml on AudienceRestriction is not defined
4-09-12T01:48:30Z" NotOnOrAfter="2014-09-12T01:54:30Z"><saml:AudienceRestriction
^
namespace error : Namespace prefix saml on Audience is not defined
0Z" NotOnOrAfter="2014-09-12T01:54:30Z"><saml:AudienceRestriction><saml:Audience
^
namespace error : Namespace prefix saml on AuthnStatement is not defined
fter="2014-09-13T01:51:30Z" SessionIndex="_59f97890-1bff-0132-6393-782bcb56fcaa"
^
namespace error : Namespace prefix saml on AuthnContext is not defined
:51:30Z" SessionIndex="_59f97890-1bff-0132-6393-782bcb56fcaa"><saml:AuthnContext
^
namespace error : Namespace prefix saml on AuthnContextClassRef is not defined
97890-1bff-0132-6393-782bcb56fcaa"><saml:AuthnContext><saml:AuthnContextClassRef
^
namespace error : Namespace prefix saml on AttributeStatement is not defined
ntextClassRef></saml:AuthnContext></saml:AuthnStatement><saml:AttributeStatement
^
namespace error : Namespace prefix saml on Attribute is not defined
Name="first_name" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"
^
namespace error : Namespace prefix saml on AttributeValue is not defined
Value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string"
^
是的,这个较大的文档是一个片段,但我需要这个片段规范化。似乎有一种方法可以告诉规范者关于在外部范围中声明的名称空间,但我不知道正确的语法。 – ysth 2014-09-14 03:17:01
有一种方法来指定它,并且我展示了它是什么。 XML文档是独立的。没有更大的范围。我不太清楚第三个参数是什么,但它应该是一个逗号分隔*前缀列表*(传递给['xmlC14NExecute'](http://xmlsoft.org/html/libxml-c14n.html #xmlC14NExecute)),它确实用于*控制输出*,不定义名称空间。 – ikegami 2014-09-14 18:23:01