Copied to clipboard

Flag this post as spam?

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


  • Jesper Lauridsen 25 posts 84 karma points
    Feb 24, 2015 @ 15:58
    Jesper Lauridsen
    0

    Transfering xml-data to webmethod...

    Hi all

    I am having a problem getting some data (xmlPathNodeIterator) from my XLST-document to a c# webmethod.
    How can that be done?

    Let me try to explain in more details;
    My XSLT document loads and display the data from an external library, which returns the data as an XPathNodeIterator (that works flawlessly).

    The idea is, that when the user click a button, the data is sent to a WebMethod, which handles further processing of the data.
    But I don't know how to get the XML-data from my XSLT-variable to jQuery - It seems that I only receive a string with all the data - not the XML-'tree'.

    I am working on a Umbraco 4.5 system.

    Anty help, that could point me in the right direction is apprecieated.

  • Kevin Jump 1867 posts 11859 karma points MVP 4x c-trib
    Feb 24, 2015 @ 16:51
    Kevin Jump
    0

    Hi,

    When you get the string with all the data is that still in xml format (so <somedata><somechild>.....</somechild></somedata>) ? 

    if so - when you are in the WebMethod you will need to load the string into an XML object. there are a couple of ways to do this. 

    depending on what you are doing. 

    you can load it into an XmlDocument 

    XmlDocument xmlDoc = new xmlDoc(); 
    xmlDoc.LoadXml(xmlString);

    from there you can manipulate the xml, do xpath ect https://msdn.microsoft.com/en-us/library/azsy1tw2(v=vs.110).aspx

    for looping through XML i prefere to use XElement, which is in System.Xml.Linq - and lets you do linq style things

    XElement element = XElement.Parse(xmlString);
    if your not even getting the xml output - i would check if you need disable-output-escaping within the xslt to preserve anything. 

     

  • Jesper Lauridsen 25 posts 84 karma points
    Feb 24, 2015 @ 17:55
    Jesper Lauridsen
    0

    Hi Kevin

    To be honest,I don't know in which format, the data I get, is - but I can use it in my XSLT-document to show data, so I would expect it to be XML. I am fairly new to XSLT, Umbraco and the whole environment, so bear with me, if I am clueless :)

    But when I try to display it with <xsl:value-of ..> it only shows me the data, not the keys/nodes. That is probably normal behavier :)

    My data-'provieder' is formatted like this;

    public static XPathNavigator getSingleDataRecord(double customerCampaignID, double clientid)
    {
           XmlDocument xmlDoc = new XmlDocument();
           NameValueCollection icCustomer = .... get data
           xmlDoc.LoadXml("<customer />");
           XmlNode stamDataNode = xmlDoc.CreateElement("basedata");
           foreach (String key in icCustomer)
           {
               XmlNode keyNode = xmlDoc.CreateElement(key);
               keyNode.AppendChild(xmlDoc.CreateTextNode(icCustomer[key]));
               stamDataNode.AppendChild(keyNode);
    
           }
           return xmlDoc.CreateNavigator();
     }
    

    In my XSLT file, I store the data in a variable, which I then use to display the data;

    <xsl:variable name="custData" select="ExternalLibrary:getSingleDataRecord(9996496, 669)" />

    My problem is, that I want to use the data in jQuery, which is calling a WebMethod to store the data on another storage.

    But I don't know how I can convert/transter the above to eg. json.

    Any pointers are apprecieated.

  • 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