如何解决XML (XACML) 语法错误 - 需要字符串文字
我正在为我的硕士论文编写 XACML 策略,但遇到明显的语法错误。它突出显示了第一行;但是,我不确定。我对 XML 很陌生,所以它可能是一个非常愚蠢的错误 :)
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<PolicySet xsi:schemaLocation="urn:oasis:names:tc:xacml:2.0:policy:schema:os
C:\Users\home\OneDrive\Documents\core-release Authzforce Testing\IIA001" PolicySetId="CAVPolicies"
PolicyCombiningAlgid="urn:oasis:names:tc:xacml:1.0:policy-combining-algorithm:permit-unless-
deny" xmlns="urn:oasis:names:tc:xacml:2.0:policy:schema:os"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Target xmlns="urn:oasis:names:tc:xacml:2.0:policy:schema:os">
</Target>
<Policy PolicyId=CAV1 RuleCombiningAlgid="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:permit-unless-deny">
<Target/>
<Rule RuleId="CAVRSU" Effect="Deny">
<Description>Vehicles will relay data to a roadside unit upon request. Attempts to read vehicle path histories,applicable lane numbers.
Calculates chance of a vehicle committing a stop violation. </Description>
<Condition>
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of">
<SubjectAttributeDesignator AttributeId="CommunicationStructure" DataType="http://www.w3.org/2001/XMLSchema#string"/>
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">RSU</AttributeValue>
</Apply>
</Apply
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of">
<ResourceAttributeDesignator AttributeId="CAVData" DataType="http://www.w3.org/2001/XMLSchema#string"/>
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Vehicle Path History</AttributeValue>
</Apply>
</Apply>
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:any-of">
<Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/>
<ActionAttributeDesignator DataType="http://www.w3.org/2001/XMLSchema#string" AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id"/>
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">READ</AttributeValue>
</Apply>
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:or">
<Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:boolean-equal"/>
<EnvironmentAttributeDesignator DataType="http://www.w3.org/2001/XMLSchema#boolean" AttributeId="VehicleWithinRSURange"/>
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#boolean">True</AttributeValue>
</Apply>
</Apply>
</Apply>
</Condition>
</Rule>
</Policy>
</PolicySet>
作为参考,我在 Notepad++ 中编写这些策略,然后在 authforce PDP 中测试它们。当我在 authforce 中运行它时,出现错误...
“线程“main”中的异常java.lang.reflect.InvocationTargetException”
对任何事情的任何反馈都非常感谢:)
解决方法
您应该习惯于查找和使用工具。我怀疑你会得到很多这样的问题的回应:) 话虽如此,这是你修改后的 xml,它不会出错。 在记事本++中,您有插件“XML 工具”。如果你安装它,并且如果你试图保存无效的 xml,它会给你错误。您还可以在您喜欢的浏览器中显示 xml 并获取错误消息。您可以看到您提供的 xml 和我使用 diff 实用程序放在下面的 xml 中的差异,我使用“winmerge (winmerge.com)”
简而言之,问题在于:
-
额外的“应用”标签
-
未关闭“应用”标签
-
policyId 属性值缺少双引号
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <PolicySet xsi:schemaLocation="urn:oasis:names:tc:xacml:2.0:policy:schema:os " PolicySetId="CAVPolicies" PolicyCombiningAlgId="urn:oasis:names:tc:xacml:1.0:policy-combining-algorithm:permit-unless-deny" xmlns="urn:oasis:names:tc:xacml:2.0:policy:schema:os" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Target xmlns="urn:oasis:names:tc:xacml:2.0:policy:schema:os"> </Target> <Policy PolicyId="CAV1" RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:permit-unless-deny"> <Target/> <Rule RuleId="CAVRSU" Effect="Deny"> <Description>Vehicles will relay data to a roadside unit upon request. Attempts to read vehicle path histories,applicable lane numbers. Calculates chance of a vehicle committing a stop violation. </Description> <Condition> <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:and"> <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of"> <SubjectAttributeDesignator AttributeId="CommunicationStructure" DataType="http://www.w3.org/2001/XMLSchema#string"/> <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag"> <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">RSU</AttributeValue> </Apply> </Apply> <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of"> <ResourceAttributeDesignator AttributeId="CAVData" DataType="http://www.w3.org/2001/XMLSchema#string"/> <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag"> <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Vehicle Path History</AttributeValue> </Apply> </Apply> <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:any-of"> <Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/> <ActionAttributeDesignator DataType="http://www.w3.org/2001/XMLSchema#string" AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id"/> <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">READ</AttributeValue> </Apply> <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:or"> <Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:boolean-equal"/> <EnvironmentAttributeDesignator DataType="http://www.w3.org/2001/XMLSchema#boolean" AttributeId="VehicleWithinRSURange"/> <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#boolean">True</AttributeValue> </Apply> </Apply> </Condition> </Rule> </Policy> </PolicySet>
@vish 的回答是正确的:您有基本的 XML 错误。您应该使用 XML 验证工具(或嵌入 Notepad ++ 或什至在线,例如 here)。此外,如果您只想编写 XACML。我建议您使用 Eclipse 和 Eclipse 的 ALFA 插件,因为编写 ALFA(然后直接转换为 XACML)要容易得多。
看看这些文章:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。