Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Amir Khan 1287 posts 2744 karma points
    Dec 15, 2014 @ 22:00
    Amir Khan
    0

    Parse XML - Get Node 2 Levels Down

    Hi, I'm trying to parse the following XML and am struggling to get the inner text from the URL node, I thought this would work "@newsRelease["PDF"].["URL"].Value.ToString()" but it returns SYSTEM.XML.XMLELEMENT.["URL"].VALUE.TOSTRING().

    Any thoughts?

    Here is the XML.

    <PDF systemGenerated="No">
    <PDFTitle>Download PDF version</PDFTitle>
    <URL>
    External.File?t=2&item=g7rqBLVLuv81UAmrh20MpzN5rpVQ1M/F/9o7oWGwNkz4OiCYsY50Vo/DnKD9u6lffF+COcZ2nL5oyR0ozpMugA==
    </URL>
    </PDF>

    Thank you,
    Amir

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 16, 2014 @ 08:38
    Dave Woestenborghs
    0

    Maybe it would help if you can post your entire code for parsing the xml ?

    Dave

  • Mike Chambers 636 posts 1253 karma points c-trib
    Dec 16, 2014 @ 09:41
  • Amir Khan 1287 posts 2744 karma points
    Dec 16, 2014 @ 16:44
    Amir Khan
    0

    Here's the rest of the code if it helps, InnerText returns SYSTEM.XML.XMLELEMENT.["URL"].INNERTEXT.

     

    @{
    //For each item node we can then ouput what we want

    foreach (XmlNode node in feedItems)
    {
    var newsReleases = node.SelectNodes("NewsRelease");
    foreach (XmlNode newsRelease in newsReleases) {
    string releaseDate = @newsRelease["Date"].Attributes["Date"].Value;
    int year = int.Parse(releaseDate.Substring(0, 4));
    int month = int.Parse(releaseDate.Substring(4, 2));
    int day = int.Parse(releaseDate.Substring(6, 2));
    DateTime releaseDateTime = new DateTime(year, month, day);

    <span></span>
    if(archiveYear == year)
    {
    <li>
    <h3>@month.@day.@year</h3>
    </li>
    } else if(archiveYear == 0 && DateTime.Now.Year == year){
    <li>
    <h1>@newsRelease.["URL"].InnerText</h1>
    <h3>@month.@day.@year</h3>

    </li>
    }

    }



    }

    }
  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 16, 2014 @ 16:46
    Dave Woestenborghs
    0

    I think you need @newsRelease["URL].InnerText instead of @newsRelease.["URL].InnerText

  • Amir Khan 1287 posts 2744 karma points
    Dec 16, 2014 @ 16:53
    Amir Khan
    0

    Hi Dave, that's actually what I had in the code above, the issue was it wasn't looking under the PDF node for the URL node.

    Here's what worked: @newsRelease.SelectSingleNode("PDF").SelectSingleNode("URL").InnerText

    Thanks,
    Amir

Please Sign in or register to post replies

Write your reply to:

Draft