Xml Namespace problem when using Submit To Hosting Environment - InfoPath Dev
in

InfoPath Dev

Xml Namespace problem when using Submit To Hosting Environment

Last post 10-20-2009 01:30 PM by zartr. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-05-2009 12:39 PM

    • zartr
    • Not Ranked
    • Joined on 11-04-2008
    • Posts 15

    Xml Namespace problem when using Submit To Hosting Environment

    hello everyone,

    I'm unable to select a single node within my xml document :-/
    http://msdn.microsoft.com/en-us/library/aa701078.aspx

    protected void XmlFormView1_Initialize(object sender, 
    InitializeEventArgs e)
    {
    // Create an XPathNavigator positioned at the root of the form's main data source.
    XPathNavigator xNavMain = XmlFormView1.XmlForm.MainDataSource.CreateNavigator();
    // Create an XmlNamespaceManager and add the "my" namespace alias from the form's main data source.
    XmlNamespaceManager xNameSpace = new XmlNamespaceManager(new NameTable());
    xNameSpace.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-04-20T16:26:21");
    // Create an XPathNavigator positioned on the form's field2.
    XPathNavigator fTextBox1 = xNavMain.SelectSingleNode("my:myFields/my:field2", xNameSpace);
    // Set the form's field2 to the value in TextBox1.
    fTextBox1.SetValue(TextBox1.Text);
    }

    First of all... my uri for the "my" namespace is different as Infopath seems to create a new uri for each xml document.
    I therefore tried to use xNavMain.LookupNamespace("my")... but that doesn't return much (null).

     

    xNavMain.SelectSingleNode("/myFields/my:forename", xNameSpace); always returns null.
    The XML as returned by XPathNavigator xNavMain = XmlFormView1.XmlForm.MainDataSource.CreateNavigator();

    <?mso-infoPathSolution name="urn:schemas-microsoft-com:office:infopath:MyEmptyTemplateFour:-myXSD-2009-07-05T16-25-14" solutionVersion="1.0.0.13" productVersion="12.0.0.0" PIVersion="1.0.0.0" href="http://portal.litwareinc.com/MyPublishingSite/MyFormsLibrary/MyTestForms/MyEmptyTemplateFour.xsn"?>
    <?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.2"?>
    <my:myFields xml:lang="en-US"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-07-05T16:25:14"
    xmlns:xd="http://schemas.microsoft.com/office/infopath/2003">
    <my:CbAllowSubmit>true</my:CbAllowSubmit>
    <my:forename></my:forename>
    <my:lastname></my:lastname>
    </my:myFields>
    It looks okay, right? 
  • 07-06-2009 09:09 AM In reply to

    • zartr
    • Not Ranked
    • Joined on 11-04-2008
    • Posts 15

    Re: Xml Namespace problem when using Submit To Hosting Environment

    I created a small workaround to read the proper uri for the "my" namespace first.
    Still I'm wondering if that's the way to go here.

  • 10-20-2009 09:48 AM In reply to

    Re: Xml Namespace problem when using Submit To Hosting Environment

    Whenever I have to select a node within code, from either the main data source or a secondary data source, I use the following:

    From Main Data Source:

    XPathNavigator nav = this.MainDataSource.CreateNavigator();
    XPathNavigator node = nav.SelectSingleNode(
    "/my:myFields/my:field1", this.NamespaceManager);

    From Secondary Data Source:

    XPathNavigator nav = this.DataSources["DataSourceName"].CreateNavigator();
    XPathNavigator node = nav.SelectSingleNode(
    "[insert xpath query here]", this.NamespaceManager);

    --andrew

  • 10-20-2009 01:30 PM In reply to

    • zartr
    • Not Ranked
    • Joined on 11-04-2008
    • Posts 15

    Re: Xml Namespace problem when using Submit To Hosting Environment

    Correct. That is if you were using that inside a form's code behind file.
    Obviously "this.NamespaceManager" won't be available once you're confronted with the xml output and the xml output only in some other application/environment/solar system for that matter.

    If I remember correctly I solved the problem by loading the whole xml data into an XmlDocument and reading the top node's namespace(s). I consider it more as a work around than a viable option but it works nonetheless.

Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.