Copied to clipboard

Flag this post as spam?

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


  • Ferdy Hoefakker 214 posts 248 karma points
    Apr 11, 2011 @ 15:17
    Ferdy Hoefakker
    0

    /base and xml

    Hey everyone, I'm trying to work with the /base functionality but something is not working like I'm expecting. I have set the config file to returnXml="true". Now, on the return page I get a nice <value> node, all the other nodes however, are not really nodes. Instead, they are simply text within the <value> node.

    Which is not what I want, as I need the function to output a well formed XML document.

    I am using Umbraco 4.5.2 btw.

    Thanks in advance,

    -Ferdy

  • Richard Soeteman 3875 posts 12037 karma points MVP
    Apr 11, 2011 @ 21:24
    Richard Soeteman
    0

    Hi Ferdy,

    The method returns an http://msdn.microsoft.com/en-us/library/system.xml.xpath.xpathnodeiterator.aspx">XpathNodeIterator instead of an XmDocument. Check the example on the msdn page how to process these nodes.

    Cheers,

    Richard

  • Ferdy Hoefakker 214 posts 248 karma points
    Apr 12, 2011 @ 09:01
    Ferdy Hoefakker
    0

    Hmm, sorry Richard but I don't really get it. The thing is, at the moment there is no XML to use an XpathNodeIterator on. I'm trying to build one in a /base function.

    string query = "my query here"

    var reader = umbraco.BusinessLogic.Application.SqlHelper.ExecuteReader(query);

    string retVal = "<users>";

    while (reader.Read())
    {
             retVal += "<user>" +
             "<campTitle>" + reader.GetString("camptitle") + "</campTitle>" +
             "</user>";
    }

    retVal += "</users>";

    return retVal;

     

    This is basically my code. When I navigate to it however, everything that gets outputted is plain text, despite my config saying I want it to return XML. So, either I am misundertanding, and I should somehow make it return an XpathNodeIterator, or there is something else I'm missing. All I see now though, is that an XpathNodeIterator needs an XML to read from, which I do not have as I am trying to build it.

    Regards,

    -Ferdy

  • Richard Soeteman 3875 posts 12037 karma points MVP
    Apr 12, 2011 @ 09:08
    Richard Soeteman
    1

    Sorry you should return an XPathNodeIterator when using the returnXml option. This is just a string, so just return as a string?

     

  • Ove Andersen 435 posts 1541 karma points c-trib
    Apr 12, 2011 @ 09:19
    Ove Andersen
    0

    Have you checked if the sample application works for you?
    http://our.umbraco.org/wiki/reference/umbraco-base/simple-base-samples

    It too returns a string.

    If you could try to implement that sample, it will be easier too see if this is an issue with your code or something else.

  • Ferdy Hoefakker 214 posts 248 karma points
    Apr 12, 2011 @ 09:28
    Ferdy Hoefakker
    0

    Yay! I got it! Thanks Richard! Returning an XPathNodeIterator was indeed just the answer I needed :D

    @Ove: No, the problem wasn't my code, it worked and returned my data. It merely returned it as plain text rather than XML. I basically got the same result as the example page, a node called "value" holding all the stuff I returned as plain text. So what I needed to know, was how to make it return my output as an XML file.

    Which it now does.

    Thanks again Richard!

    Regards,

    -Ferdy

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies