.例えばh2要素の内容をラベルとしてメタデータファイルに保持しておきたいとします。
<h2><abbr title="Document Object Model">DOM</abbr> と XPath</h2>
このようなh2要素の場合、「DOM と Xpath」という文字列をラベルにします。h2要素がコンテクストノードであるなら、string(self::node())がそれを表します。ところが次のようにソース整形のための空白文字(改行含む)が入っていると、その空白文字が含まれた別の値になってしまいます。
<h2>
<abbr title="Document Object Model">DOM</abbr>
と XPath
</h2>
normalize-space関数を使って正規化すれば同じ値になります。(normalize-space(string(self::node())))
XPathのnormalize-space()関数による正規化の際にはこのような処理が行われるわけですが、DOM1のElementインターフェイス(DOM2では確かNodeインターフェイス)のnormalizeメソッドによる正規化は異なります。「隣接するテキストノードを一つにする」だけで、空白文字については何の処理もしてくれません。DOMで操作した直後のツリー構造と、文書を読み込んだ時のツリー構造が異なってしまうのを防ぐためにあるメソッドです(多分)。
これらをdataとしたテキストノードをある空要素hに連続してappendChildしたとします。この段階では、hをコンテクストノードとしたロケーションパス: child::text()[1]は「No War」で、child::text()[2]が「No peace」になっています。しかしh要素をnormalizeすると、二つの隣接したテキストノードは連結され、child::text()[1]は「No war No peace 」になります。
……と、あまり関係ない話ですが、normalize-space()関数の動作と混同している人を見かけたので一応書いておきました。
ISO-HTMLのような"フラットな"構造をもったXML文書の、各セクションを個別に更新した際、その差分をどうやって比較しようかという話です。
<h2>Section1</h2>
<p>para1</p>
<p>para2</p>
<h2>Section2</h2>
<p>para1</p>
<p>para2</p>
これは二つのセクションの構造を簡潔に表現したものです。「物語風XML(XHTML等)」では、要素名や属性値はメタデータ的な、付加情報的なものであり、XMLとして同一であるか否かを比較せずとも、その内容を比較すれば十分であると思われます。つまり物語風XMLにおいては、マークアップの修正は更新とは呼ばず、その内容の変更が更新と呼ばれるものと仮定します。
従って、各セクションの「内容」を参照することから始めます。
appendChildします。descendant::text()を参照します。具体的な方法はDOMとXPathの実装に依存しますが、この方法だと比較的直感的に参照できると思います。
その内容は、メタデータとして保持しておく必要がありますが、ここで問題となるのは、セクションの一意性です。折角内容を保持しても更新されたセクションとの対応関係が分からなければ利用できません。HTMLでいえばid属性を持たせれば良いのですが、これが実に鬱陶しい。文書を作成する上では見出しを考えるだけでも一苦労なのに、その上メタデータとしての識別子をも考えねばならないのは馬鹿げています。
海外(英語圏)では、見出しの語句をそのままアンダースコア "_" 等で連結したものをidにすることで自動化している例がありますが、日本語の場合、HTML等のフォーマットに変換する際に障壁になってきます。また、私は物語風XMLは直接編集したいので、ソースが汚くなってしまうことは避けなければなりません。id属性のような編集と無関係なものは、分離しておきたいのです。
ここで考えたのが、パブリックな位置で利用され得る普遍的な識別子と、ローカルで活用する識別子を分けてしまう方法です。
前者、つまりHTMLのid属性のような普遍的識別子は、秒単位の作成日時を元に作成します。後者は、識別子というよりも差分を比較する際のラベルとして利用するもので、見出しの文字列をそのまま利用します。両者はともに、XML文書内には記述せずにサイトマップなどのメタデータファイルに分離させて管理します。
このようにすることで、編集が楽になり、ソースはシンプルになり、見出しのちょっとした変更も行うことが出来るようになります。
注意点としては、一つのXML文書内に同一の見出しの登場が許されないため、例でいうh2要素をID型にしてスキーマでチェックする必要があるという点です。
つづく……かもしれない。...redesign in progress.
なんか特命リサーチ?か何かで取り上げられていた馬鹿メールがうちにも来たので記念に公開しておきます。
「南アフリカから"お金"を移動させたいので協力してくれ」といったような内容なのですが、「協力」を申し出ると空港に出迎えが待っていて、個室に連れて行かれて大量の真っ黒なお札が入ったジュラルミンケースを見せられ、これを元に戻すためと称して数百万円を要求されるのだとか(うろ覚え)。笑い。
Return-Path: <matelo@mail.co.za>
Received: by femail23.im.home.ne.jp with ESMTP
id <20030415195702.BCIJ1948.femail23.im.home.ne.jp@mx204.mf.home.ne.jp>
for <jintrick@jcom.home.ne.jp>; Wed, 16 Apr 2003 04:57:02 +0900
Received: from mail2.mcn.ne.jp (mail2.mcn.ne.jp [210.233.74.242])
by mx204.mf.home.ne.jp (m23033100) with SMTP id h3FJv1oE017305
for <jintrick@jcom.home.ne.jp>; Wed, 16 Apr 2003 04:57:01 +0900 (JST)
Received: (qmail 17798 invoked by alias); 15 Apr 2003 19:57:01 -0000
Delivered-To: w650s@mcn.ne.jp
Received: (qmail 17767 invoked by uid 0); 15 Apr 2003 19:57:00 -0000
Received: from mail.acc.co.za (HELO webmail.mail.co.za) (192.96.58.70)
by mail2.mcn.ne.jp with SMTP; 15 Apr 2003 19:57:00 -0000
X-WM-Posted-At: webmail.mail.co.za; Tue, 15 Apr 03 19:45:38 +0200
X-WebMail-UserID: matelo
Date: Tue, 15 Apr 2003 19:45:38 +0200
Sender: "kenneth Matelo.M" <matelo@mail.co.za>
From: "kenneth Matelo.M" <matelo@mail.co.za>
To: k_mbagi@phantomemail.com
Subject: Hello
Message-ID: <3E9CE655@webmail.mail.co.za>
Mime-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 7bit
X-Mailer: InterChange (Hydra) SMTP v3.61.01
Mr. Kenneth Mbagi
P. O. Box 32, Shaka,
Bulawayo, Zimbabwe.
Tel : Your Intl. Access Code : + 88216 52098236
Emai : k_mbagi@phantomemail.com
Dear Sir/Madam
You may be surprised to receive this letter from me since you do not
know me personally. For the purpose of introduction, I am Mr. Kenneth
Mbagi, the son of Dr. Matelo Mbagi, a wealthy farmer/politician in
Zimbabwe who was recently murdered in the land dispute in my country.
I got your contact through the internet based on our urgent need for a
dependable and trustworthy foreign partner. Hence I decided to write
to you.
Before the death of my late father, he had taken me to Johannesburg to
deposit the sum total of US$20.5 million (Twenty million, Five Hundred
thousand United States dollars), in one of the private security
companies, as he foresaw the looming danger in Zimbabwe. This money
was deposited in two boxes as Family Treasures to avoid much demurrage
from the security company. This amount was meant for the purchase of
new machines and chemicals for the Farms and the establishment of new
farms in Swaziland.
The land problem, in our country came when our President Mr. Robert
Mugabe in a bid to win his re-election, introduced a new Land Act
Reform wholly affecting the rich white farmers and some few black
farmers who are members of the opposition party. This resulted in
killings and mob action by Zimbabwean war veterans and some lunatics
in the society. A lot of people have been killed because of this Land
reform Act for which my father was unfortunately one of the victims.
It is against this background that, I and my family fled Harare our
capital for fear of our lives and are currently staying in a remote
country side of Bulawayo. We are planning to leave the country and
seek political asylum in Europe and we have decided to move our family
wealth to Europe.
As the eldest son of my father, I am saddled with the responsibility
of seeking a genuine partner that could assist us without the
knowledge of my government who are bent on taking everything we have
got, and the South African government seems to be playing along with
them. I am faced with the dilemma of moving this amount of money out
of South Africa for fear of going through the same experience in
future, since both countries have similar political history.
I am now seeking for a partner whom I have to entrust my future and
that of my family in his/her hands. To this end, we need your
assistance to stand as the Beneficiary of the Consignments in Europe.
This is because we are under restricted movement and watch and hence
we want to be very careful in order not to lose this fund which we
have worked so hard for. I have a sufficient CONTACT person at the
Security Company in South Africa who can help us move this money to
Europe under DIPLOMATIC COVER to another Security Company in Europe
with your details as the Beneficiary. This is 100% legal and will not
pass through normal Customs/Airport Screening.
Thus, if you are willing to assist us to move this fund out of South
Africa, you can contact me through my email addresses, Tel no. above
with your telephone, fax number and personal information to enable us
discuss further details. I must let you know that this transaction is
risk free as far as we keep it as confidential as possible.
Thank you, many blessings to you.
Yours Faithfully,
Mr. Kenneth Mbagi. k_mbagi@phantomemail.com
N/B : Please dial directly, do not include my country code i.e. (263).
just dial your country Intl. access code + 88216 52098236