1

How to retrieve List item values from a Component using the Core Services. Below is the xml.

<FaqCategory xmlns="http://www.xyz.com/tridion/schemas">
    <Title>Denied boarding compensation options</Title>
    <url>Denied boarding compensation options</url>
    <List xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="tcm:229-2468565" xlink:title="120. When will I get my voucher and where do I collect it from?"></List>
    <List xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="tcm:229-2468581" xlink:title="210. Can I upgrade my compensation ticket using my Skywards Miles?"></List>
    <List xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="tcm:229-2468568" xlink:title="140. Can I give the voucher to family or friends?"></List>
</FaqCategory>

In a string builder I want the output to be:

"120. When will I get my voucher and where do I collect it from?","210. Can I upgrade my compensation ticket using my Skywards Miles?".

I tried using regex but no use. Please suggest.

1

Using RegEx to parse XML will probably drive you insane.

Here's a somewhat rushed way to parse your XML...

string xml = "<FaqCategory xmlns=\"http://www.xyz.com/tridion/schemas\"><Title>Denied boarding compensation options</Title><url>Denied boarding compensation options</url><List xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:type=\"simple\" xlink:href=\"tcm:229-2468565\" xlink:title=\"120. When will I get my voucher and where do I collect it from?\"></List><List xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:type=\"simple\" xlink:href=\"tcm:229-2468581\" xlink:title=\"210. Can I upgrade my compensation ticket using my Skywards Miles?\"></List><List xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:type=\"simple\" xlink:href=\"tcm:229-2468568\" xlink:title=\"140. Can I give the voucher to family or friends?\"></List></FaqCategory>";
XDocument xdoc = XDocument.Parse(xml);
string faqNs = "http://www.xyz.com/tridion/schemas";
string xlinkNs = "http://www.w3.org/1999/xlink";

StringBuilder s = new StringBuilder();

XElement rootNode = xdoc.Element(XName.Get("FaqCategory", faqNs));

s.Append("Title: ");
s.Append(rootNode.Element(XName.Get("Title", faqNs)).Value);
s.Append(Environment.NewLine);
s.Append("Url: ");
s.Append(rootNode.Element(XName.Get("url", faqNs)).Value);
s.Append(Environment.NewLine);
foreach (XElement node in rootNode.Elements(XName.Get("List", faqNs)))
{
    s.Append(node.Attribute(XName.Get("title", xlinkNs)).Value);
    s.Append(Environment.NewLine);
}

Console.WriteLine(s.ToString());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.