Reading from an external XML file. - InfoPath Dev
in

InfoPath Dev

Reading from an external XML file.

Last post 06-14-2007 08:11 AM by davidair. 18 replies.
Page 1 of 2 (19 items) 1 2 Next >
Sort Posts: Previous Next
  • 06-12-2007 07:40 AM

    • seadsead
    • Not Ranked
      Male
    • Joined on 06-12-2007
    • Ottawa, Ontario, Canada
    • Posts 14

    Reading from an external XML file.

    Hey,

     

    I'm new to the forums, so i hope this is not a repeat question. (I looked so I don't think so)

    I was wondering if it is possible to read from an external XML file (not the files that go with the form, i.e.: in a different path location)

    btw I'm using vbs for scripting.

     

    thanks

  • 06-12-2007 07:59 AM In reply to

    Re: Reading from an external XML file.

    You can read any XML file the same way, whether or not it's included in the form:

    set xmlDocument = XDocument.CreateDOM()
    xmlDocument.async =
    false
    xmlDocument.load(pathToYourFile)

    set xmlDocument = XDocument.CreateDOM()
    xmlDocument.async =
    false
    xmlDocument.load(pathToYourFile)

    Important note: 

    If pathToYourFile points to a general filename somewhere on the system, your solution must be full-trust which is often a pain (you either need to sign it or to install it)

    If pathToYourFile points to a relative filename that is included in your form, your solution does not have to be full-trust

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-12-2007 10:25 AM In reply to

    • seadsead
    • Not Ranked
      Male
    • Joined on 06-12-2007
    • Ottawa, Ontario, Canada
    • Posts 14

    Re: Reading from an external XML file.

    thanks a bunch.

     I'm getting an access denied ERROR now.
    And my form is Full-trust,

    here's a an example of the erronious line.:

    xmlDoc.load("C:\Temp\Test.xml")

    Any ideas??

  • 06-12-2007 11:47 AM In reply to

    Re: Reading from an external XML file.

    Hmm... how did you set your form to be full-trust? How are you testing it? If you are using IP2003, you cannot preview in full-trust so that could be your problem.

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-12-2007 11:59 AM In reply to

    • seadsead
    • Not Ranked
      Male
    • Joined on 06-12-2007
    • Ottawa, Ontario, Canada
    • Posts 14

    Re: Reading from an external XML file.

    I created a cert to test.

    I am using IP2003, but I'm not trying to use the preview because of the trust problem.
    I launch it from the form externaly.

    It's been working fine until now.
    It's only since i tried to load teh XML file that I've been getting this problem.
    I've tried from Network drives and Localy (i.e. C: drive)

    any clues?

  • 06-12-2007 12:18 PM In reply to

    Re: Reading from an external XML file.

    Couple of ideas:

    1. There is a problem with the certificate and so the form is not *really* running as full trust. To check this, try to run Application.Quit() from your code - if this fails, the form is not really executing as full trust

    2. The file is not accessible so you get a true "access denied" (this is less likely, I think #1 is the more likely culprit)

     

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-12-2007 12:25 PM In reply to

    • seadsead
    • Not Ranked
      Male
    • Joined on 06-12-2007
    • Ottawa, Ontario, Canada
    • Posts 14

    Re: Reading from an external XML file.

    Well,

     #1 Works, so thats out.

    And, I don't think the file is not accessible, because I'm modifying it.  How can it not be accessible?

    I have a feeling this is gonna take me a while, lol

    thanks for the input aswell.

  • 06-12-2007 12:39 PM In reply to

    • seadsead
    • Not Ranked
      Male
    • Joined on 06-12-2007
    • Ottawa, Ontario, Canada
    • Posts 14

    Re: Reading from an external XML file.

    I can only get it to work when the XML file is in the same folder as the form(s).

    I really hope there is a way around this

  • 06-12-2007 02:03 PM In reply to

    Re: Reading from an external XML file.

    Hmm... this is strange... if you are running full-trust and the file is accessible, I am not sure what else could be wrong.

    One thing you could try is to use the FSO object to load the file as text. Here is an MSDN example that shows you how to do this: http://msdn2.microsoft.com/en-us/library/t58aa4dd.aspx

    If you can get the XML in this way then you can use the loadXml() method on the newly created DOM to suck the XML in.

    Let me know if this workaround works!

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-13-2007 06:29 AM In reply to

    • seadsead
    • Not Ranked
      Male
    • Joined on 06-12-2007
    • Ottawa, Ontario, Canada
    • Posts 14

    Re: Reading from an external XML file.

    I've already tried this, and it works fine.

    But my group would rather have it in XML. (Though, if I can't get this working with XML, then Txt it is, lol)

    thanks again,
          Let me know if you come across a way to get XML working maybe.

  • 06-13-2007 06:34 AM In reply to

    Re: Reading from an external XML file.

    Well, if you can get it as text first then you can get it as XML by doing LoadXml(). Let me know if the load-as-text trick works!
    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-13-2007 11:27 AM In reply to

    • seadsead
    • Not Ranked
      Male
    • Joined on 06-12-2007
    • Ottawa, Ontario, Canada
    • Posts 14

    Re: Reading from an external XML file.

    LoadXml() seems to work great.

    Now I'm having trouble reading nodes, or even getting a NodeList.

    this is really starting to get on my nerves, lol

  • 06-13-2007 11:47 AM In reply to

    Re: Reading from an external XML file.

    So you can finally get your XML file into a DOM, right? Great!

    If you share out our XML file and the code you use to read it maybe I could see why you're failing to read the data.

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-13-2007 12:26 PM In reply to

    • seadsead
    • Not Ranked
      Male
    • Joined on 06-12-2007
    • Ottawa, Ontario, Canada
    • Posts 14

    Re: Reading from an external XML file.

    I'm trying to have an external Software list(in XML format) to read from, that we can change if needed (New Specialty software available on our network)
    Right now I just want to write to an external Text file to make sure I'm getting stuff(Testing only)

    this is what I've got so far:

    Dim xmlDoc, nodeList

    Set xmlDoc = XDocument.CreateDOM()
    xmlDoc.async = false xmlDoc.LoadXml(path to XML File)

          Set nodeList = xmlDoc.SelectNodes("descendant::SoftwareList[Software/sName = *]")
    or
          Set nodeList = xmlDoc.GetElementsByTagName("sName")
                        
                          BOTH WORKED IN PREVIOUS FORMS

    Dim fso, testFile
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set testFile = fso.CreateTextFile("C:\Temp\testfile.txt",True)

    testFile.WriteLine(xmlDoc.GetElementsByTagName("sName").item(0).text)  'test for data
                                                              ^--- this is where the errors are coming from

    testFile.Close


    The ERROR I'm getting is:  Object required: 'xmlDoc.GetElementsByTagName(...).item(...)'

    this is the test XML file.

    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <SoftwareList>
      <Software>
        <sName>Adobe Reader 8</sName>
      </Software>
      <Software>
        <sName>WinZip 11.1</sName>
      </Software>
    </SoftwareList>

    I don't understand what I'm doing wrong?

  • 06-13-2007 06:47 PM In reply to

    Re: Reading from an external XML file.

    Well, loadXml takes an xml string of a form "<tag><anotherTag/>...</tag>", not a path to a file. So first you need to load the text from file using FSO and then you can load it into an xml document via loadXml

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
Page 1 of 2 (19 items) 1 2 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.