私はSDLTridion2011SP1でTom.NetAPIに取り組んでいます。XhtmlFieldの「ソース」部分を取得しようとしています。
私の情報源は次のようになります。
<Content>
<text>
<p xmlns="http://www.w3.org/1999/xhtml">hello all<strong>
<a id="ID1" href="#" name="ZZZ">Name</a>
</strong></p>
</text>
</Content>
この「テキスト」フィールドのソースを取得し、名前が付いたタグを処理したいと思いますa
。
私は次のことを試みました:
ItemFields content = new ItemFields(sourcecomp.Content, sourcecomp.Schema);
XhtmlField textValuesss = (XhtmlField)content["text"];
XmlElement textxmlelement = textValuesss.Definition.ExtensionXml;
Response.Write("<BR>" + "count:" + textxmlelement.ChildNodes.Count);
for (int i = 0; i < textxmlelement.ChildNodes.Count; i++)
{
Response.Write("<BR>" + "nodes" + textxmlelement.ChildNodes[i].Name);
}
//get all the nodes with the name a
XmlNodeList nodeswithnameA = textxmlelement.GetElementsByTagName("a");
foreach (XmlNode eachNode in nodeswithnameA)
{
//get the value at the attribute "id" of node "a"
string value = eachNode.Attributes["id"].Value;
Response.Write("<BR>" + "idValue" + value);
}
出力がありません。さらに、私はゼロとしてカウントを取得しています。
私が得た出力:
カウント:0
フィールドにいくつかの子タグがありますが、0がとして来る理由がわかりませんCount
。
必要な変更を提案できますか。
ありがとうございました。