including xml inline html documents

M

Michael Hill

I was wondering if it is possible to include a xml structure in your html
document.

For example given the below snippet the function "dothis()" will return 0
and "dothat()" will return 1.

If I can use xml in html I should be returning 1 for both functions.

Thanks,

Mike

<script>
function dothis()
{
var xxx = document.getElementById('xmlid');
alert(xxx.childNodes.length);
}
function dothat()
{
var xxx = document.getElementById('tblid');
alert(xxx.childNodes.length);
}
</script>

<xml id="xmlid">
<data>
<first>abc</first>
</data>
</xml>

<table id="tblid">
<tr>
<td>abc</td>
</tr>
</table>
 
V

VK

<xml> is just a wrapper for Microsoft Data Island.
Do start working with the XML data itself, you have to go one more level
down, and after that use the standard DOM methods for XML objects.

From your example:

function dothis() {
var xxx = xmlid.XMLDocument.selectSingleNode('data/first');
alert(xxx.text);
}
....
<xml id="xmlid">
<data>
<first>abc</first>
</data>
</xml>
 
M

Michael Hill

VK said:
<xml> is just a wrapper for Microsoft Data Island.
Do start working with the XML data itself, you have to go one more level
down, and after that use the standard DOM methods for XML objects.

From your example:

function dothis() {
var xxx = xmlid.XMLDocument.selectSingleNode('data/first');
alert(xxx.text);
}
...
<xml id="xmlid">
<data>
<first>abc</first>
</data>
</xml>
vk, thanks for that start. using this script:

var myxml = xmlid.XMLDocument;
var myroot = myxml.documentElement;
var myNodes = myroot.childNodes;
for ( i=0; i<myNodes.length; i++ )
{
alert(myNodes.item(i).firstChild.nodeValue);
}

and this xml

<xml id="xmlid">
<data>
<first>abc</first><second>xyz</second>
</data>
</xml>

I get "abc", "xyz" as predicted, but when I change my xml adding another
record it does not.

<xml id="xmlid">
<data>
<first>abc</first><second>xyz</second>
</data>
<data>
<first>def</first><second>dfr</second>
</data>
</xml>

i can't get my node pointer positioned correctly.

Mike
 
M

Martin Honnen

Michael Hill wrote:

but when I change my xml adding another
record it does not.

<xml id="xmlid">
<data>
<first>abc</first><second>xyz</second>
</data>
<data>
<first>def</first><second>dfr</second>
</data>
</xml>

i can't get my node pointer positioned correctly.

Well it is called XML data island as you are supposed to have XML in
there and XML needs to have exactly one root element to contain all
other elements e.g.
<xml id="xmlid">
<root>
<data>
<first>abc</first><second>xyz</second>
</data>
<data>
<first>def</first><second>dfr</second>
</data>
</root>
</xml>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top