Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 8 of 8

Thread: Baffled... how do I import an XML file into an XML package?

  1. #1
    dkmooers is offline Junior Member
    Join Date
    Nov 2011
    Posts
    6

    Default Baffled... how do I import an XML file into an XML package?

    I've been going around and around for hours on this. I'm trying to import an XML file that describes a static menu into a custom XML package and transform it to HTML.

    Here's the innards of my XML package:

    Code:
    <xsl:template match="/">
    	<xsl:copy-of select="document('menuDataBootstrap.xml')" />
    	<xsl:value-of select="document('menuDataBootstrap.xml')" />
    	<xsl:apply-templates select="bootstrapmenu" />								
    </xsl:template>
    	
    	
    <xsl:template match="bootstrapmenu">
    	<li>MENU HOLY CRAP WITHIN BOOTSTRAPMENU TAMPLATE!</li>
    		<xsl:for-each select="level1">
                             ... etc.
    </xsl:template>
    And here's the XML file:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <bootstrapmenu>
    
    	<level1 Text="Home" NavigateNavigateUrl="default.aspx?skinid=2">
    	</level1>
    	
    	<level1 Text="Instruments" NavigateUrl="c-2-instruments.aspx?skinid=2">
    		<level2 Text="Steel String Guitars" NavigateUrl="c-3-steel-string-guitars.aspx?skinid=2"/>
    	</level1>
    ... etc.
    </bootstrapmenu>
    Problem is, the XML package pulls in the XML, but it gets written into an xfrm.xml.config file, called bootstrapmenu.xml.config_store.xfrm.xml. It's not getting written into the store.runtime.xml file, which I think it should be. The result? The XML file I want to pull in is not getting transformed into HTML. I just get a blank HTML output on my site.

    (I've also tried embedding C# into my template.ascx to do the XSL transformation of the XML, but having trouble doing that. I'd like to avoid touching TemplateBase.cs, too, if at all possible.)

    This is crazy! Seems like it should be so easy to just import an XML document into the XML package and transform it using XSL inside the XML package. If I use this code, though, it crashes the server:

    Code:
    <xsl:apply-templates select="document('menuDataBootstrap.xml')" />
    Help is much appreciated! I'm practically tearing out my hair over this!

  2. #2
    dkmooers is offline Junior Member
    Join Date
    Nov 2011
    Posts
    6

    Default

    Anyone have any ideas?

  3. #3
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    I've never tried doing this before, but that doesn't mean it isn't possible.

    First question, have you tried stepping through the source code? Do you know what line crashes?

    Second, why have you broken you XML documents up like this? Why not keep them together?
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM

  4. #4
    dkmooers is offline Junior Member
    Join Date
    Nov 2011
    Posts
    6

    Default

    Thanks for the reply! Have not stepped through source code... not sure how to do that! (I'm mainly an HTML/CSS developer. I'm doing this website for a small business with small resources, so they don't have the cash at the moment to hire an experienced ASPDNSF developer.)

    Second, what do you mean by splitting up XML documents? My idea was to have one XML menu document that someone in this small business (music retail store) can edit down the road without knowing too much programming. Then, the XML package reads in the XML and translates it to HTML inside template.ascx. Is there a different way I could be doing this?

  5. #5
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    If you don't own the source code, which if your not in Visual Studio, then you probably don't, then you can't set through the source to find the error. If you post the screen shot/text of the error with debugging mode turned on you can see more about where the error is coming from and I might be able to provide more specific help.

    As for what I mean by one file: if you look at the other XML packages in ASPDNSF you'll see that all the code for rendering the page is in one single file. I suggest that you do the same. I understand about wanting to make things easy to edit, but that is probably best accomplished by putting like 10 lines of comments above and below the code that they should modify, perhaps even describing modifications they are likely to want to make or, better yet, include the original code so that if they mess something up, they can start over.

    This way, all the code will be in a single file, so your error will go away, and it will still be easy to edit because you've commented the file well. Make sense?
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM

  6. #6
    dkmooers is offline Junior Member
    Join Date
    Nov 2011
    Posts
    6

    Default

    Makes great sense! That may be the best way to do it at this point. Is there any way, though, to include XML in the XML package and have an XSL template that transforms it? The reason I'd like to use XML is so I can do something like this:

    Code:
    <bootstrapmenu>
    
    	<level1 Text="Home" NavigateNavigateUrl="default.aspx?skinid=2">
    	</level1>
    	
    	<level1 Text="Instruments" NavigateUrl="c-2-instruments.aspx?skinid=2">
    		<level2 Text="Steel String Guitars" NavigateUrl="c-3-steel-string-guitars.aspx?skinid=2"/>
    	</level1>
    
    </bootstrapmenu>
    That will be much easier to edit than the actual HTML that needs to be used by Bootstrap, which is more like this:

    Code:
    <ul class="nav">
      <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
          Instruments
          <b class="caret"></b>
        </a>
        <ul class="dropdown-menu">
          ...
        </ul>
      </li>
    </ul>
    That's pretty messy and would be easy to screw up. Hence writing it in XML to make it editable by the average human. Is this possible within an XML package?

  7. #7
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    I've never tried including XML in an XML package, but you might consider storing the data you need in a database table and then using a SQL query to retrieve it. Then it will be an XML file.

    I would imagine there has to be a way to specify an XML source for an XML package though.

    In fact, this might prove helpful:

    CreateXmlFromDelimitedString
    Description:
    Sample:

    Argument Name: delimitedString
    Data Type: string
    Description:

    Argument Name: delimiter
    Data Type: string
    Description:

    Argument Name: rootname
    Data Type: string
    Description:

    Argument Name: elementname
    Data Type: string
    Description:

    Generally speaking, I would have a look at this really closely: http://manual.aspdotnetstorefront.co...-packages.aspx.
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM

  8. #8
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default

    You should be able to pull the xml file in through a WebQuery.

    Take a look at the following from the link cjbarth posted above :-


    Code:
      <webquery name=”WebData1” RetType=”xml”> 
        <url>http://www.somesite.com/xmldatafeed.aspx?param1={param1}</url> 
        <querystringreplace replaceTag=”{param1}” replacetype=”request” 
          replaceparamname=”productid” defvalue=”0”
          validationpattern=”^\d{1,10}$”/> 
      </webquery>
    I've only ever done this for xml data coming from another server - but see no reason why it couldn't access the same domain as the store.


    TTFN

    BFG