Getting the complete XML source for an Xhtml field using the Tom.Net API in SDL Tridion 2011 SP1

I am working on the Tom.Net API in SDL Tridion 2011 SP1. I am trying to get the "source" part of XhtmlField.

My source looks like this.

<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>

I want to get the source of this text field and process the tags with the name a.

I tried the following:

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);
}

I do not get any output. Moreover, I get the score as zero.

The output I received is:

quantity: 0

Although I have several child tags in the field, I don’t understand why 0 comes like Count.

Can anyone suggest the necessary changes.

Thank.

+5
source share
2 answers

ItemField.Definition , , ExtensionXml ( ). .

, XML/XHTML, Content , XmlElement. , XmlNamespaceManager XmlElement. , "":

XmlNameTable nameTable = new NameTable();
XmlNamespaceManager nsManager = new XmlNamespaceManager(nameTable);
nsManager.AddNamespace("custom", sourceComp.Content.NamespaceURI);
XmlElement fieldValue = (XmlElement)sourceComp.Content.SelectSingleNode(
                                "/custom:Content/custom:text", nsManager);
+8
textValuesss.Definition.ExtensionXml

( , ExtensionXml - XML-, ).

textValuesss.Value XML. , , SelectSingleNode XPath, XHTML. Linq XML, .

+2

All Articles