How to access a secondary data source xml file - InfoPath Dev
in

InfoPath Dev

How to access a secondary data source xml file

Last post 12-16-2005 12:15 AM by mar. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 12-14-2005 02:31 AM

    • mar
    • Top 500 Contributor
    • Joined on 09-04-2005
    • Poland
    • Posts 37

    How to access a secondary data source xml file

    I have secondary data source "workers.xml".And i have a textbox field1 on my form. Now, i want to use a field1 value to get from workers.xml a person with id=field1 value.How can i do that in c#?
  • 12-14-2005 04:43 AM In reply to

    • mar
    • Top 500 Contributor
    • Joined on 09-04-2005
    • Poland
    • Posts 37

    Re: How to access a secondary data source xml file

    Ok, solved it(thanks forhttp://infopathdev.com/forums/topic.asp?TOPIC_ID=88).
    But now,i cant get any data.My code looks like that:
    -----------------------------------------------------------
    DataObject obj = thisXDocument.DataObjects["workers.xml"];
    IXMLDOMDocument3 domXML = (IXMLDOMDocument3) obj.DOM;
    domXML.setProperty("SelectionNamespaces","xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-12-01T19:27:12\"");
    IXMLDOMNode worker = obj.DOM.selectSingleNode("/my:myFields/my:workers/my:worker[my:id=1]/child..login");
    [...]
    row.selectSingleNode("my:pracownik").nodeTypedValue=worker.text;
    ------------------------
    And im getting
    "System.NullReferenceException: Object reference not set to an instance of an object"
    on this last line of code (row.selected...).I have field 'pracownik' on my form and my 'workers.xml' file looks like that:
    [..]
    <my:workers>
    <my:worker>
    <my:id>1</my:id>
    <my:name>john</my:name>
    </my:worker>
    <my:worker>
    <my:id>2</my:id>
    <my:name>tod</my:name>
    </my:worker>
    [...]
    </my:workers>

    Where is a mistake?

    --------------------------------------------------------
  • 12-14-2005 06:36 AM In reply to

    Re: How to access a secondary data source xml file

    The XPath in this statement looks really weird:

    IXMLDOMNode worker = obj.DOM.selectSingleNode("/my:myFields/my:workers/my:worker[my:id=1]/child..login");

    What is "child..login" at the end? If you want the name, change it to "my:name". The reason your getting an error on the line that you're getting them on is because the line listed above is initializing the 'worker' variable to null because your XPath does not return any nodes.

    ---------------
    Matt Faus
    InfoPath Dev Texas
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 12-14-2005 06:53 AM In reply to

    • mar
    • Top 500 Contributor
    • Joined on 09-04-2005
    • Poland
    • Posts 37

    Re: How to access a secondary data source xml file

    Doesnt matter what is written here,
    IXMLDOMNode worker = obj.DOM.selectSingleNode("/my:myFields/my:workers/my:worker[my:id=1]/my:name");
    or
    IXMLDOMNode worker = obj.DOM.selectSingleNode("/my:myFields/my:workers/my:worker/my:name");
    i cant make this work. I want to get name with id from my primary source,from textbox on my form.But now i just want to know, that it works and gets anything from this workers.xml...
  • 12-14-2005 07:01 AM In reply to

    • mar
    • Top 500 Contributor
    • Joined on 09-04-2005
    • Poland
    • Posts 37

    Re: How to access a secondary data source xml file

    Maby there is another way of getting a data from secondary data source file?im really frustrated...
  • 12-15-2005 02:01 AM In reply to

    Re: How to access a secondary data source xml file

    You need the goo to select the namespaces.

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 12-15-2005 07:14 AM In reply to

    • mar
    • Top 500 Contributor
    • Joined on 09-04-2005
    • Poland
    • Posts 37

    Re: How to access a secondary data source xml file

    Forgive me, but..whats 'goo'?:)
  • 12-15-2005 12:12 PM In reply to

    Re: How to access a secondary data source xml file

    http://en.wikipedia.org/wiki/Goo_%28Gumby_character%29

    Sorry, couldn't resist! Anyway, I'm not sure - in InfoPath if you double-click on the node that you are trying to access and go the to the Details tab there is information about the namespace there.

    ---------------
    Matt Faus
    InfoPath Dev Texas
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 12-16-2005 12:15 AM In reply to

    • mar
    • Top 500 Contributor
    • Joined on 09-04-2005
    • Poland
    • Posts 37

    Re: How to access a secondary data source xml file

    goo,well...ok ;)
    I solved my problem, i had to use /ns3:..../ns3:..... instead of /my:....,for my secondary data source. I dont know why, but it works now.
Page 1 of 1 (9 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.