http://www.f1project.org/xml/laboratorio.php
shows us a XML file but it dosent end in .xml and i dont know why,
but is it possible to get vb6 to read the xml? and if so how?
thanks
Printable View
http://www.f1project.org/xml/laboratorio.php
shows us a XML file but it dosent end in .xml and i dont know why,
but is it possible to get vb6 to read the xml? and if so how?
thanks
I get an error when I open that. Maybe you can open the link in a WebBrowser control and get the XML from page source.
oh you have to be logged into the website.
it doesn't end in xml because what you are accessing is a PHP file... it just so happens that the php file then returns an XML document. Having to be logged into the website adds a bit of complexity... and I'm not sure quite how to deal with that.
-tg
well logging in from the program is something i might try at a later date, at the moment i'm just happy with loggin in in my browser, and then reading the xml doc.
apparently its because the file is dynamically generated
still stuck
think i am getting it to read the url now,
just trying to get a textbox to display the value of a node
but it bugs when trying to find the node
any ideas where i might be going wrong?
vb Code:
Private Sub Command46_Click() Dim objXML As MSXML2.DOMDocument Dim objElem As MSXML2.IXMLDOMElement Set objXML = New MSXML2.DOMDocument If objXML.Load("http://www.f1project.org/xml/laboratorio.php") = False Then MsgBox ("XML LOAD ERROR") Else Set objElem = objXML.selectSingleNode("//LaboratoryAeroPrice") <------ it bugs here Text4.Text = objElem.getAttribute("value") End If End Sub
a bit of the xml i'm trying to use:
<Laboratory>
<LaboratoryAeroInv>0</LaboratoryAeroInv>
<LaboratoryElectInv>5000</LaboratoryElectInv>
<LaboratoryMotorInv>15000</LaboratoryMotorInv>
<LaboratoryTyresInv>15000</LaboratoryTyresInv>
<LaboratoryGearInv>0</LaboratoryGearInv>
<LaboratorySuspenInv>25000</LaboratorySuspenInv>
<LaboratoryBrakeInv>15000</LaboratoryBrakeInv>
<LaboratoryAeroLev>1</LaboratoryAeroLev>
<LaboratoryElectLev>8</LaboratoryElectLev>
<LaboratoryMotorLev>11</LaboratoryMotorLev>
<LaboratoryTyresLev>11</LaboratoryTyresLev>
<LaboratoryGearLev>1</LaboratoryGearLev>
<LaboratorySuspenLev>12</LaboratorySuspenLev>
<LaboratoryBrakeLev>10</LaboratoryBrakeLev>
<LaboratoryPieceBuilded>5</LaboratoryPieceBuilded>
<LaboratoryAeroBuilded>0</LaboratoryAeroBuilded>
<LaboratoryElectBuilded>1</LaboratoryElectBuilded>
<LaboratoryMotorBuilded>1</LaboratoryMotorBuilded>
<LaboratoryTyresBuilded>1</LaboratoryTyresBuilded>
<LaboratoryGearBuilded>0</LaboratoryGearBuilded>
<LaboratorySuspenBuilded>1</LaboratorySuspenBuilded>
<LaboratoryBrakeBuilded>1</LaboratoryBrakeBuilded>
<LaboratoryAeroPrice>2525</LaboratoryAeroPrice>
<LaboratoryElectPrice>8742</LaboratoryElectPrice>
<LaboratoryMotorPrice>38651</LaboratoryMotorPrice>
<LaboratoryTyresPrice>12704</LaboratoryTyresPrice>
<LaboratoryGearPrice>2525</LaboratoryGearPrice>
<LaboratorySuspenPrice>25264</LaboratorySuspenPrice>
<LaboratoryBrakePrice>29946</LaboratoryBrakePrice>
</Laboratory>
I think you are getting the error because of this line
If I am not wrong, then the syntax isQuote:
If objXML.Load("http://www.f1project.org/xml/laboratorio.php")
If Not objXML.loadXML(strXML) Then
Where strXML is a string variable which stores XML and not a website address...
Example
Regarding the code in post 6, I don't see any syntax errors...Code:strXML = "<JustAnExample><Node Name=""tag666""/><group name=""VBF""><another value=""VBForums""/></group></JustAnExample>"
i used to think it was that line, but wouldn't it come up with that msgbox if it couldn't load it?
but i'm using a url and how would i update the xml data from the url into a string automatically?,
seems a bit pointless, there must be a way to just use the url?
Can you try this for me and tell me what happens?
Code:Private Sub Command46_Click()
Dim objXML As MSXML2.DOMDocument
Dim objElem As MSXML2.IXMLDOMElement
Dim strXML As String
Set objXML = New MSXML2.DOMDocument
strXML = "<Laboratory><LaboratoryAeroInv>0</LaboratoryAeroInv><LaboratoryAeroPrice>2525</LaboratoryAeroPrice></Laboratory>"
If objXML.LoadXML(strXML) = False Then
MsgBox ("XML LOAD ERROR")
Else
Set objElem = objXML.selectSingleNode("//LaboratoryAeroPrice")
Text4.Text = objElem.getAttribute("value")
End If
End Sub
koolsid - there's two methods to load - Load which takes a filepath OR a URL to an XML doc... so that part is OK. LoadXML is a DIFFERENT function, that, like you mentioned, takes an XML string...
In this case the Load (with the url) is the appropriate syntax.
The reason objXML.selectSingleNode("//LaboratoryAeroPrice") fails is because the xPath query is wrong.
LaboratoryAeroPrice isn't a root node... Laboratory is the root node... so to get to the AeroPrice, the selection should be:
objxml.documentElement.selectSingleNode("/Laboratory/LaboratoryAeroPrice")
I find that selecting right off the document doesn't seem to work, but going through the documentElelment object does.... go figure.
-tg
with koolsid's get the msgbox.
with techgnome i get an error saying "Object variable or With block variable not set"
I had made a typo in the last post. Try it now:)
ok that gets to the getAttribute bit but it errors and says "invalid use of Null"
but i want it from a url
See if this helps you...
http://www.xml.com/pub/a/2000/07/12/...b_and_xml.html
That's because it isn't an attribute.... once you have the node, you should be able to get the value through .Value or .InnerHTML ...
-tg
with techgnome i get an error saying "Object variable or With block variable not set"
Text4.Text = objElem.Value
Text4.Text = objElem.InnerHTML
both dont work :(
i still cant get the value into the textbox?
any ideas?