need help with responsexml

Author Message
thenson81

  • Total Posts : 8
  • Scores: 0
  • Reward points : 0
  • Joined: 12/18/2011
  • Status: offline
need help with responsexml Sunday, December 18, 2011 2:25 PM (permalink)
0
Hi all,
 
I am having an issue with being able to work with an .xml across the network (will be a web service).
I have a function that takes in a object that has a url in it.  I do not have any issues getting to the web addresses and I know this because if I use  wscript.echo http.responsetext    it will show all of the xml file on the screen.
However when I try to use set xmlData = http.responsexml  so that I can start parsing the file, I keep getting object required errors.
 
for testing I did try doing a wscript.echo xmlData.xml  and this actually displayed xml for only 1 of the 4 addresses I passed to it.
I also tried using the other option of microsoft.xmlhttp       MSXML2.XMLHTTP and still same errors. 
 
Public Function isUpdated(update)
Dim HTTP, xmlData
Set HTTP = CreateObject("Microsoft.xmlhttp")
http.open "GET", update.uri, FALSE
http.setRequestHeader "Content-Type", "text/xml"
http.send

set xmlData = http.responsexml
set childnodes = xmldata.documentelement.childnodes ' THIS IS WHERE I GET OBJECT ERRORS ON DOCUMENTELEMENT
 for each node in childnodes
    wscript.echo node.nodename
        next
set http = nothing
end Function
 
 
part of one of the xml files I am trying to parse is (I can't show all of the files as this is work related):
 
 
<?xml version="1.0" encoding="utf-8" ?>
- <manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" manifestId="22739229-7e40-4e93-936f-6a35523b59fb" mandatory="No" xmlns="urn:schemas-microsoft-com:PAG:updater-application-block:v2:manifest">

   </manifest>
 
I am only trying to grab the manifestId out of the files.... Any ideas?
Thanks!



 
#1
    Wakawaka

    • Total Posts : 456
    • Scores: 23
    • Reward points : 0
    • Joined: 8/27/2009
    • Status: offline
    Re:need help with responsexml Monday, December 19, 2011 1:10 AM (permalink)
    0
    Maybe a silly question, but is there actually a root element or are all of these elements just in the body of the XML document after the processing instructions?
     
    #2
      thenson81

      • Total Posts : 8
      • Scores: 0
      • Reward points : 0
      • Joined: 12/18/2011
      • Status: offline
      Re:need help with responsexml Monday, December 19, 2011 2:04 AM (permalink)
      0
      I am not sure if I am following your question but here is more of what the xml's look like.
       
      <manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" manifestId="22739229-7e40-4e93-936f-6a35523b59fb" mandatory="No" xmlns="urn:schemas-microsoft-com:PAG:updater-application-block:v2:manifest">

        <description>Update - 12/9/2011 9:08:51 AM</description>

      - <application applicationId="Client">
        <location>Incoming</location>

        </application>


      -  <file source="XMLSchema.zip" transient="No" />
        <file source="ClientSettings.txt" transient="No" />

        </files>


      - <activation>
      </activation> - <tasks>
      </tasks>



      </manifest>
      I have to omit a lot of the file information as Im not sure if I can get into any trouble from work, but that is the basic format.
      I just tried this here again and it appears that I am having issues returning from 1  server (possibly different segment?).
      If I do the following:
      Public Function isUpdated(update)
      Dim HTTP
      Set HTTP = CreateObject("Microsoft.xmlhttp")
      Set xmlDoc = CreateObject("Microsoft.xmlDOM")
      http.open "GET", update.uri, FALSE
      http.setRequestHeader "Content-Type", "text/xml"
      http.send
      xmldoc.async=false
      xmldoc.load(http.responsexml)
      set xmldoc = nothing
      set xmlData = http.responsexml


       
       
       
      It will print the xml from all the servers except one, it prints blank (probably null returned).
      What doesn't make sense though is if I do set xmldata = http.responsetext
       
      It will show the text from all servers if I print it.....
       
      these .xmls  are all set up the same just in different locations in the network.
       
      #3
        TNO

        • Total Posts : 2094
        • Scores: 36
        • Reward points : 0
        • Joined: 12/18/2004
        • Location: Earth
        • Status: offline
        Re:need help with responsexml Monday, December 19, 2011 4:42 AM (permalink)
        0
        thenson81

        [...]
        It will print the xml from all the servers except one, it prints blank (probably null returned).
        What doesn't make sense though is if I do set xmldata = http.responsetext

        It will show the text from all servers if I print it.....

        these .xmls  are all set up the same just in different locations in the network.


        The server is probably not giving you the proper content-type. Even if the file is a properly formatted xml, if the content-type does not match it will not be interpreted properly.

        For example:
         Dim Dom : Set Dom = CreateObject("MSXML2.DomDocument.6.0") 
         With Dom 
         .async = False 
         .load "http://validator.w3.org/"  'Fail 
         .load "http://ht2012.org/" 'Success 
         WScript.Echo .documentElement.xml 
         End With 


        Even though <http://validator.w3.org/> is a properly formatted XML file, the content-type is not set to be xml by the server, so it won't be interpreted as such.
        <http://ht2012.org/> on the other hand is served with the proper mime-type by the server and works fine.

        What to do? You could fix the server to return the proper mime-type. Alternatively, you could use XMLHTTP to get the .responseText and then pass that directly to

        CreateObject("MSXML2.DomDocument.6.0").loadXML "xml string"

        similar to how I have done above.

        To iterate is human, to recurse divine. -- L. Peter Deutsch
         
        #4
          thenson81

          • Total Posts : 8
          • Scores: 0
          • Reward points : 0
          • Joined: 12/18/2011
          • Status: offline
          Re:need help with responsexml Monday, December 19, 2011 6:00 AM (permalink)
          0
          thanks for the replay.
          What I have tried is saving them to temp . xml file and then loading that into xml object. 
           
          I am not sure how your syntax is supposed to work but I tried it and it just gives me errors.
           
          Thanks for your help
           
          And now I am having issues with not being able to pull the manifestID line from here:
          <?xml version="1.0" encoding="utf-8"?>
          <manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" manifestId="{1e95ea16-d7fc-422f-92f9-15f991a59f09}" mandatory="Yes" xmlns="urn:schemas-microsoft-com:PAG:updater-application-block:v2:manifest">
           
          isn't this just an attribute?  when it try to get attributes it says its an invalid method. 
           
           
           
          set manifestNode = xmlDoc.getelementsbytagname("manifest")

          for each n in manifestNode
          wscript.echo  n.nodename
          does print out "manifest"    buttrying to set  m = manifestNode.attributes   says its invalid
          <message edited by thenson81 on Monday, December 19, 2011 6:36 AM>
           
          #5
            Wakawaka

            • Total Posts : 456
            • Scores: 23
            • Reward points : 0
            • Joined: 8/27/2009
            • Status: offline
            Re:need help with responsexml Monday, December 19, 2011 7:26 AM (permalink)
            0
            For the attribute, you have to use the .GetAttribute("attributeName") method of the xml node.
             
            Is there a tag that contains the Manifest node?  As for the content-type, that should be something the webserver is passing to you.  I am not the most experienced with retrieving web XML data though.
             
            #6
              thenson81

              • Total Posts : 8
              • Scores: 0
              • Reward points : 0
              • Joined: 12/18/2011
              • Status: offline
              Re:need help with responsexml Monday, December 19, 2011 8:20 AM (permalink)
              0
              set manifestNode = xmldoc.getelementsbytagname("manifest")
              manifestProperties = manifestNode(0).getattribute("manifestId")
               
              worked thanks a lot!  I didnt' know of the getattribute
               
              #7

                Online Bookmarks Sharing: Share/Bookmark

                Jump to:

                Current active users

                There are 0 members and 1 guests.

                Icon Legend and Permission

                • New Messages
                • No New Messages
                • Hot Topic w/ New Messages
                • Hot Topic w/o New Messages
                • Locked w/ New Messages
                • Locked w/o New Messages
                • Read Message
                • Post New Thread
                • Reply to message
                • Post New Poll
                • Submit Vote
                • Post reward post
                • Delete my own posts
                • Delete my own threads
                • Rate post

                2000-2012 ASPPlayground.NET Forum Version 3.9