Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to load XML result in VbScript

Status
Not open for further replies.

venusgirrl

Programmer
Dec 26, 2007
7
BR
Hi,

Maybe the answer for my question is easy, but I am so new to xml, I tried a lot of ways but all of them dont work.

I have a page (made by another person), and it works correctly, but where the page calls the results of the xml is not where I need.

The header:
<HTML>
<HEAD>
<XML id="DIVIDA">
</XML>
<script language="JavaScript">
DIVIDA.load(top.DIVIDA);
...
</script>
</head>

Then I have the body and it uses the table span to show the results:
<table width="84%" border="0" cellspacing="0" cellpadding="0" class="fonte5" datasrc="#DIVIDA">
<tr>
<td colspan="1"><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">
Contract nº: <b><span datasrc="#DIVIDA" datafld="CONTRACT"></span></b></font></td>
...
</body>
OK, it works perfectly!!!

The challenge I am facing is, instead of showing the CONTRACT number, I need to show the company it belongs to, to do that I need a select Case.

For example:
Case CONTRACT = "000001001"
sText = "Contract from the Company 1"
Case CONTRACT = "000002001"
sText = "Contract from the Company 2"

But I need to build this Select Case instruction before the <body> using VbScript and then pass the variable sText to the html body.

What instruction do I use to pass the variable CONTRACT to my Select Case using VbScript?

Hope someone could help!!
Thanks in advance,
venus
 
I am millimeter away from red-flag this. If you have a pure vbs or js syntax problem, ask the appropriate forum. Besides, don't know what those are, top.DIVIDA etc... and why it is needed to do thing in this case with a mixture of vbs and js.
[tt]
'vbs version
select case CONTRACT
case "000001001"
sText = "Contract from the Company 1"
case "000002001"
sText = "Contract from the Company 2"
case else
'do nothing
end select

//js version
switch (CONTRACT) {
case "000001001":
sText = "Contract from the Company 1";
break;
case "000002001":
sText = "Contract from the Company 2";
break;
default:
//do nothing
}
[/tt]
Any further questions should be directed to vbscript and javascript forums (use search if you don't know where).
 
well, I am talking about get a result of a xml in the head section of my page, my problem is not pass the value to vb script. Thats the reason why I posted my question here, as far I know my doubt is about xml.

But If you think, its a Vb Script question, please do red flag this.

 
Well, I will red flag to my best judgement. But, if you don't want help from this forum, you are free to do. You select case format is way off, mind you and I do give you good correction.
 
The problem is, I need help from a XML forum.
I would appreciate If you could help me then
 
<HTML>
<HEAD>
<XML id="DIVIDA">
</XML>
then after this I need to make a select case
but how can I get the values of this xml (DIVIDA) in my select case.
got it??
...
<body>
...
 
By one way or another such as an event handler, call the function such as this and you see how that kind of data is retrieved. (Here the first contract is retrieved, else, you loop through all.)
[tt]
<script language="javascript">
function findit() {
var sText;
var DIVIDA=document.getElementById("DIVIDA"); //better practice
var s=DIVIDA.getElementsByTagName("CONTRACT")[blue][0][/blue].text;
switch (s) {
case "000001001":
sText = "Contract from the Company 1";
break;
case "000001002":
sText = "Contract from the Company 2";
break;
default:
sText = "not identified"
}
//do whatever with the finding such as: return sText
alert(sText);
}

</script>
[/tt]
 
Ok, Thank you tsuji :)
But I need to recover like this:

<script type="text/vbscript">
set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load(DIVIDA)
--
here I need the value of CONTRACT, but I dont know how to access it, I am trying to loop thru the nodes but it isnt working.
--
</script>
</head>

Cuz I need to pass this value to the body of my document, inside of a <div> element.
Maybe its clearer now
 
But your data-island has no src. What is going on? If it has src or you have some onload to set up its src, then you don't need another instance of xmlDoc. The object DIVIDA (referring it by id, ie-proprietory) is already by itself a DOMDocument object. In that case, you simply apply dom-supported method to get it.
[tt]
<script type="text/vbscript">
dim s
s=DIVIDA.getElementsByTagName("CONTRACT")(0).text
msgbox s 'for illustration
</script>
[/tt]
But you have to make sure it is executed _after_ the data-island fully loaded and ready.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top