我讨厌XML

XML现在被越来越广泛的应用了,不过我觉得它已经变了,本来它是为了简单,容易读懂而设计的,但是现在,它彻底变成了只有机器才能读懂的东西。可恶的是,我的工作中还是要经常读XML文档,有时候甚至要读XML Schema来确定一个文档的合法性-_-。号称最好的XML SPY,也就那么回事,编辑起来一点都不方便。 一个例子就是XACML。这个东西是BEA和EnTrust,Sun等公司合伙搞出来的一个OASIS标准,用来表述授权的策略。我们公司以前的一个产品,也有一种自己发明的授权策略表述语言。如果要表示这么一个策略: 当用户user_1访问resource_1的时候,具有role_1的角色 用我们以前的表述语言,大概这么写: grant( user_1, resource_1, role_1 ) 如果用XACML来表述,就得象下面这样。实在是,让人无法恭维。呵呵,大概就是为了软件公司能赚钱吧。。。 <Policy xmlns=”urn:oasis:names:tc:xacml:2.0:policy:schema:os“ PolicyId=”urn:bea:xacml:2.0:entitlement:role:permitRole“ RuleCombiningAlgId=”urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable“> <Target> <div> <div> <div> <div> <a href="http://themouse.spaces.live.com/mmm2006-11-30_19.10/#"><strong><span style="font-family: Courier New; color: #ff0000;">&#8211;</span></strong></a> <span><span style="color: #0000ff;"><</span></span><span><span style="color: #990000;">Resources</span></span><span><span style="color: #0000ff;">></span></span> </div> <div> <div> <div> <a href="http://themouse.spaces.live.com/mmm2006-11-30_19.10/#"><strong><span style="font-family: Courier New; color: #ff0000;">&#8211;</span></strong></a> <span><span style="color: #0000ff;"><</span></span><span><span style="color: #990000;">Resource</span></span><span><span style="color: #0000ff;">></span></span> </div> <div> <div> <div> <a href="http://themouse.spaces.live.com/mmm2006-11-30_19.10/#"><strong><span style="font-family: Courier New; color: #ff0000;">&#8211;</span></strong></a> <span><span style="color: #0000ff;"><</span></span><span style="color: #990000;"><span>ResourceMatch</span><span> MatchId</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>urn:oasis:names:tc:xacml:1.0:function:string-equal</strong><span style="color: #0000ff;"><span>&#8220;</span><span>></span></span> </div> <div> <div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"><</span></span><span style="color: #990000;"><span>AttributeValue</span><span> DataType</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>http://www.w3.org/2001/XMLSchema#string</strong><span style="color: #0000ff;"><span>&#8220;</span><span>></span></span><span><strong><span style="background-color: #ffff00;">resource_1</span></strong></span><span><span style="color: #0000ff;"></</span></span><span><span style="color: #990000;">AttributeValue</span></span><span><span style="color: #0000ff;">></span></span> </div> </div> <div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"><</span></span><span><span style="color: #990000;">ResourceAttributeDesignator</span></span> <span><span style="color: #990000;">AttributeId</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>urn:oasis:names:tc:xacml:2.0:resource:resource-ancestor-or-self</strong><span><span style="color: #0000ff;">&#8220;</span></span><span><span style="color: #990000;"> DataType</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>http://www.w3.org/2001/XMLSchema#string</strong><span><span style="color: #0000ff;">&#8220;</span></span><span><span style="color: #990000;"> MustBePresent</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>true</strong><span style="color: #0000ff;"><span>&#8220;</span><span> /></span></span> </div> </div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"></</span></span><span><span style="color: #990000;">ResourceMatch</span></span><span><span style="color: #0000ff;">></span></span> </div> </div> </div> <div> <div> <a href="http://themouse.spaces.live.com/mmm2006-11-30_19.10/#"><strong><span style="font-family: Courier New; color: #ff0000;">&#8211;</span></strong></a> <span><span style="color: #0000ff;"><</span></span><span style="color: #990000;"><span>ResourceMatch</span><span> MatchId</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>urn:oasis:names:tc:xacml:1.0:function:string-equal</strong><span style="color: #0000ff;"><span>&#8220;</span><span>></span></span> </div> <div> <div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"><</span></span><span style="color: #990000;"><span>AttributeValue</span><span> DataType</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>http://www.w3.org/2001/XMLSchema#string</strong><span style="color: #0000ff;"><span>&#8220;</span><span>></span></span><span><strong><span style="background-color: #ffff00;">role_1</span></strong></span><span><span style="color: #0000ff;"></</span></span><span><span style="color: #990000;">AttributeValue</span></span><span><span style="color: #0000ff;">></span></span> </div> </div> <div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"><</span></span><span><span style="color: #990000;">ResourceAttributeDesignator</span></span> <span><span style="color: #990000;">AttributeId</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>urn:oasis:names:tc:xacml:2.0:subject:role</strong><span><span style="color: #0000ff;">&#8220;</span></span><span><span style="color: #990000;"> DataType</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>http://www.w3.org/2001/XMLSchema#string</strong><span><span style="color: #0000ff;">&#8220;</span></span><span><span style="color: #990000;"> MustBePresent</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>true</strong><span style="color: #0000ff;"><span>&#8220;</span><span> /></span></span> </div> </div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"></</span></span><span><span style="color: #990000;">ResourceMatch</span></span><span><span style="color: #0000ff;">></span></span> </div> </div> </div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"></</span></span><span><span style="color: #990000;">Resource</span></span><span><span style="color: #0000ff;">></span></span> </div> </div> </div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"></</span></span><span><span style="color: #990000;">Resources</span></span><span><span style="color: #0000ff;">></span></span> </div> </div> </div> <div> <div> <a href="http://themouse.spaces.live.com/mmm2006-11-30_19.10/#"><strong><span style="font-family: Courier New; color: #ff0000;">&#8211;</span></strong></a> <span><span style="color: #0000ff;"><</span></span><span><span style="color: #990000;">Actions</span></span><span><span style="color: #0000ff;">></span></span> </div> <div> <div> <div> <a href="http://themouse.spaces.live.com/mmm2006-11-30_19.10/#"><strong><span style="font-family: Courier New; color: #ff0000;">&#8211;</span></strong></a> <span><span style="color: #0000ff;"><</span></span><span><span style="color: #990000;">Action</span></span><span><span style="color: #0000ff;">></span></span> </div> <div> <div> <div> <a href="http://themouse.spaces.live.com/mmm2006-11-30_19.10/#"><strong><span style="font-family: Courier New; color: #ff0000;">&#8211;</span></strong></a> <span><span style="color: #0000ff;"><</span></span><span style="color: #990000;"><span>ActionMatch</span><span> MatchId</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>urn:oasis:names:tc:xacml:1.0:function:anyURI-equal</strong><span style="color: #0000ff;"><span>&#8220;</span><span>></span></span> </div> <div> <div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"><</span></span><span style="color: #990000;"><span>AttributeValue</span><span> DataType</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>http://www.w3.org/2001/XMLSchema#anyURI</strong><span style="color: #0000ff;"><span>&#8220;</span><span>></span></span><span><strong>urn:oasis:names:tc:xacml:2.0:actions:enableRole</strong></span><span><span style="color: #0000ff;"></</span></span><span><span style="color: #990000;">AttributeValue</span></span><span><span style="color: #0000ff;">></span></span> </div> </div> <div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"><</span></span><span><span style="color: #990000;">ActionAttributeDesignator</span></span> <span><span style="color: #990000;">AttributeId</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>urn:oasis:names:tc:xacml:1.0:action:action-id</strong><span><span style="color: #0000ff;">&#8220;</span></span><span><span style="color: #990000;"> DataType</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>http://www.w3.org/2001/XMLSchema#anyURI</strong><span><span style="color: #0000ff;">&#8220;</span></span><span><span style="color: #990000;"> MustBePresent</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>true</strong><span style="color: #0000ff;"><span>&#8220;</span><span> /></span></span> </div> </div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"></</span></span><span><span style="color: #990000;">ActionMatch</span></span><span><span style="color: #0000ff;">></span></span> </div> </div> </div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"></</span></span><span><span style="color: #990000;">Action</span></span><span><span style="color: #0000ff;">></span></span> </div> </div> </div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"></</span></span><span><span style="color: #990000;">Actions</span></span><span><span style="color: #0000ff;">></span></span> </div> </div> </div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"></</span></span><span><span style="color: #990000;">Target</span></span><span><span style="color: #0000ff;">></span></span> </div> </div> </div> <div> <div> <a href="http://themouse.spaces.live.com/mmm2006-11-30_19.10/#"><strong><span style="font-family: Courier New; color: #ff0000;">&#8211;</span></strong></a> <span><span style="color: #0000ff;"><</span></span><span style="color: #990000;"><span>Rule</span><span> RuleId</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>primary-rule</strong><span><span style="color: #0000ff;">&#8220;</span></span><span><span style="color: #990000;"> Effect</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>Permit</strong><span style="color: #0000ff;"><span>&#8220;</span><span>></span></span> </div> <div> <div> <div> <a href="http://themouse.spaces.live.com/mmm2006-11-30_19.10/#"><strong><span style="font-family: Courier New; color: #ff0000;">&#8211;</span></strong></a> <span><span style="color: #0000ff;"><</span></span><span><span style="color: #990000;">Condition</span></span><span><span style="color: #0000ff;">></span></span> </div> <div> <div> <div> <a href="http://themouse.spaces.live.com/mmm2006-11-30_19.10/#"><strong><span style="font-family: Courier New; color: #ff0000;">&#8211;</span></strong></a> <span><span style="color: #0000ff;"><</span></span><span style="color: #990000;"><span>Apply</span><span> FunctionId</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>urn:oasis:names:tc:xacml:1.0:function:string-is-in</strong><span style="color: #0000ff;"><span>&#8220;</span><span>></span></span> </div> <div> <div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"><</span></span><span style="color: #990000;"><span>AttributeValue</span><span> DataType</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>http://www.w3.org/2001/XMLSchema#string</strong><span style="color: #0000ff;"><span>&#8220;</span><span>></span></span><span><strong><span style="background-color: #ffff00;">user_1</span></strong></span><span><span style="color: #0000ff;"></</span></span><span><span style="color: #990000;">AttributeValue</span></span><span><span style="color: #0000ff;">></span></span> </div> </div> <div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"><</span></span><span><span style="color: #990000;">SubjectAttributeDesignator</span></span> <span><span style="color: #990000;">AttributeId</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>urn:oasis:names:tc:xacml:1.0:subject:subject-id</strong><span><span style="color: #0000ff;">&#8220;</span></span><span><span style="color: #990000;"> DataType</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>http://www.w3.org/2001/XMLSchema#string</strong><span><span style="color: #0000ff;">&#8220;</span></span><span><span style="color: #990000;"> SubjectCategory</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>urn:oasis:names:tc:xacml:1.0:subject-category:access-subject</strong><span style="color: #0000ff;"><span>&#8220;</span><span> /></span></span> </div> </div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"></</span></span><span><span style="color: #990000;">Apply</span></span><span><span style="color: #0000ff;">></span></span> </div> </div> </div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"></</span></span><span><span style="color: #990000;">Condition</span></span><span><span style="color: #0000ff;">></span></span> </div> </div> </div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"></</span></span><span><span style="color: #990000;">Rule</span></span><span><span style="color: #0000ff;">></span></span> </div> </div> </div> <div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"><</span></span><span><span style="color: #990000;">Rule</span></span> <span><span style="color: #990000;">RuleId</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>deny-rule</strong><span><span style="color: #0000ff;">&#8220;</span></span><span><span style="color: #990000;"> Effect</span></span><span><span style="color: #0000ff;">=&#8221;</span></span><strong>Deny</strong><span style="color: #0000ff;"><span>&#8220;</span><span> /></span></span> </div> </div> <div> <span><strong><span style="font-family: Courier New; color: #ff0000;"> </span></strong></span> <span><span style="color: #0000ff;"></</span></span><span><span style="color: #990000;">Policy</span></span><span><span style="color: #0000ff;">></span></span> </div>

十二月 15, 2006 · Shawn Ma