Custom import - InfoPath Dev
in

InfoPath Dev

Custom import

Last post 01-15-2006 10:42 PM by Coita Thierry. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 10-18-2005 01:03 PM

    Custom import

    Does anyone know where a really good custom import tutorial is? I have found some that are pretty vague, and some that help you translate XML into XHTML, but I need to know how to import an XML into my XML InfoPath document. Thanks for any help! (Maybe Patrick/Greg will write one for the How-To section?)

    ---------------
    Matt Faus
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 10-18-2005 03:13 PM In reply to

    Well, I'm making my way (rather slowly) through the SDK and I did find an example form that is much more helpful. I have gotten a few steps to work, such as actually recognizing that I have a custom XSL file and use it when the merge form request has the same namespace as the schema file I have set to undergo the XSL tranformation.

    I have been manually opening the form and going to File -> Merge Forms... to test out and see if my XSL is working correctly, but how can I do this programmatically? I have a secondary data source which is included as a resource file within my form. I want to "custom merge" this secondary XML file into my primary DOM using XSL whenever the user changes to the "Print View". I know about the onSwitchView() event, but what would the code look like to do a XSL merge? I have tried a couple things with XDocument.ImportDOM() and .ImportFile(), but it kept giving me a "This method is not allowed with this object." error.

    Any help is greatly appreciated :)

    ---------------
    Matt Faus
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 10-19-2005 11:16 PM In reply to

    Hi Matt,
    Yes, this has been on our HowTo list for a long time. We have several samples of doing this, but no time this week. Couple hints are that it's easier to debug code than the XSLT. The Program Manager for this feature suggests writing code OnMergeRequest to do the custom merge since the XSLT can be hard to figure out.

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 01-12-2006 07:32 AM In reply to

    • rleist
    • Not Ranked
    • Joined on 01-12-2006
    • Posts 7
    I'm trying to do something similar to this. I want to populate a repeating table with queried data from a secondary data source. I've been trying to use the transformNode() method with a XSL stylesheet but it gives me an error that the stylesheet does not contain a document element. Does transformNode() only convert to XHTML and not to XML? Any other method of doing this?

    Stylesheet:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:d="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"
    xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"
    xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-11-09T19:54:35"
    xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" version="1.0">

    <xsl:output encoding="UTF-8" method="xml"/>
    <xsl:template match="/">
    <xsl:for-each select="d:tblServer">
    <my:qServer>
    <my:qServerName><xsl:value-of select="@ServerName" /></my:qServerName>
    <my:qManufacturer><xsl:value-of select="d:tblManufacturers[@MfgName]" /></my:Manufacturer>
    <my:qModel><xsl:value-of select="d:tblManufacturerModels[@ModelName]" /></my:qModel>
    <my:qActive><xsl:value-of select="@Active" /></my:qActive>
    <my:qRecordID><xsl:value-of select="@ServerID" /></my:qRecordID>
    </my:qServer>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

    Code:

    function queryam::OnClick(eventObj)
    {
    var objADOAdapter, re, strNewSQL, strSQL;
    var objServerName = XDocument.DOM.selectSingleNode( "//my:ServerForm/my:ServerName" );

    if (objServerName.text == "")
    {
    XDocument.UI.Alert("Please enter a server name to query for.");
    return
    };

    objADOAdapter = XDocument.DataObjects("AssetManager").QueryAdapter;
    re = /order by \"ServerName\"/g;
    strSQL = objADOAdapter.Command;
    strNewSQL = strSQL.replace(re, "where (\"ServerName\" like '%" + objServerName.text + "%') order by \"ServerName\"");
    objADOAdapter.Command = strNewSQL;
    XDocument.DataObjects.Item("AssetManager").Query();
    objADOAdapter.Command = strSQL;
    var XMLFileDOM = XDocument.GetDOM("AssetManager")
    var objAMServer = XMLFileDOM.selectSingleNode( "//d:tblServer" );
    var objQuerySelect = XDocument.DOM.selectSingleNode( "//my:ServerForm/my:QuerySelect" );
    objQuerySelect.text = objAMServer.getAttribute("ServerID")
    var objxsl = XDocument.CreateDOM()
    objxsl.async = false
    objxsl.load("trans.xsl")
    objAMServer = XMLFileDOM.selectSingleNode( "//dfs:dataFields" );
    objQuerySelect = XDocument.DOM.selectSingleNode( "//my:ServerForm/my:qServers");
    objQuerySelect.text = objAMServer.transformNode(objxsl);
    }
  • 01-12-2006 08:02 AM In reply to

    • rleist
    • Not Ranked
    • Joined on 01-12-2006
    • Posts 7
    OK, I just realized that it is not loading my xsl file. I added the file as a resourse file. How do I reference a resource file in code? I just have:

    objxsl.load("trans.xsl")
  • 01-13-2006 09:07 AM In reply to

    I don't know if I correctly understood the question: I wrote nice subs in vb to import in one form nodes coming from another form where both forms are referring to the same template.
    For example an user can import rows from the same repeating table in another form.

    Bye
  • 01-15-2006 10:42 PM In reply to

    Hi Matt,

    You need to add your xsl as a ressource file and after in your script you can make your:

    objxsl.load("trans.xsl")

    You can find additonnal help here:

    http://support.microsoft.com/kb/827005/en-us

    Thierry
    Infopath 2007, Langage: C#2.0 (Modèle Objet 2003)
    merci de lire ceci
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.