<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <record> <Name>Name1</Name> <Address>Addresstreet 1</Address> <City>City</City> <Telephone>123123</Telephone> </record>
<record> <Name>Name 2</Name> <Address>Address</Address> <City>City 2</City> <Telephone>345345-345345</Telephone> </record>
</data-set>
I normally load jQuery and a few helper scripts into this hidden webview for DOM access and to make use of a lot of the jQuery code available on the net :)
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
You may need to look into:
window.DOMParser
instead of the microsoft way - pretty sure that won't work in a droid webview.
app.LoadScript("marknote.js");function OnStart(){
str = app.ReadFile( "Lijst_technieken.xml" ); var parser = new marknote.Parser(); var doc = parser.parse(str); root=new marknote.Element(); root=doc.getRootElement() len=children = root.getChildElements().length; for (var i = 0; i < len; i++) { var child = root.getChildElementAt(i); var Name = child.getChildElement("Name").getContents(); var Address= child.getChildElement("Address").getContents(); alert(Name + Address); }}
I am adding that library into my snippets.
Im sorry, I know, but can you solve this problem?
Once you have installed the plugin, there is a simple example that parses XML to a useful JavaScript object at
Docs > Plugins > Xml2Js
var xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+
'<root>'+
" <a>'orses</a>"+
' <b>mutton</b>'+
' <c>looking</c>'+
' <d>ential</d>'+
'</root>'
app.LoadPlugin( "Xml2Js" );
function OnStart()
{
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
btn = app.CreateButton( "Press Me" );
btn.SetOnTouch( Parse );
lay.AddChild( btn );
plg = app.CreateXml2Js();
app.AddLayout( lay );
}
function Parse()
{
plg.ParseString( xml, OnResult );
}
function OnResult( err, result )
{
//alert( JSON.stringify(result,null,1) );
alert("C for " + result.root.c);
}
var xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+
'<root>'+
" <a>'orses</a>"+
' <b>mutton</b>'+
' <c>looking0</c>'+
' <c>looking1</c>'+
' <c>looking2</c>'+
' <d>ential</d>'+
'</root>'
app.LoadPlugin( "Xml2Js" );
function OnStart()
{
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
btn = app.CreateButton( "Press Me" );
btn.SetOnTouch( Parse );
lay.AddChild( btn );
plg = app.CreateXml2Js();
app.AddLayout( lay );
}
function Parse()
{
plg.ParseString( xml, OnResult );
}
function OnResult( err, result )
{
// alert( JSON.stringify(result,null,1) );
alert(result.root.c[1]);
}
function OnResult( err, result )
{
var max = result.root.c.length - 1;
alert("max = " + max +
"\n"+result.root.c[max] );
}
alert(result.TrainingCenterDatabase.Activities.Activity.Lap.Track.Trackpoint.Time) ;
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<TrainingCenterDatabase xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2">
<Activities>
<Activity Sport="Other">
<Id>2017-01-19T13:27:19.866Z</Id>
<Lap StartTime="2017-01-19T13:27:19.866Z">
<TotalTimeSeconds>1800</TotalTimeSeconds>
<DistanceMeters>6604</DistanceMeters>
<Calories>344</Calories>
<Intensity>Active</Intensity>
<TriggerMethod>Manual</TriggerMethod>
<Track>
<Trackpoint>
<Time>2017-01-19T13:27:19.866Z</Time>
<Position>
<LatitudeDegrees>0.0</LatitudeDegrees>
<LongitudeDegrees>0.0</LongitudeDegrees>
</Position>
<DistanceMeters>1</DistanceMeters>
<HeartRateBpm>
<Value>96</Value>
</HeartRateBpm>
alert(result.TrainingCenterDatabase.Activities[0].Activity[0].Lap[0].Track[0].Trackpoint[0].Time[0]._)