Looking to extract GML data and integrate it with Unity.
Below is my C# script for XML parsing:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Xml.Linq;
using System.Linq;
using UnityEngine.UI;
public class Manager_02 : MonoBehaviour
{
public GameObject text01;
private void Start()
{
string path = @"C:unitySample.gml";
XDocument xd = XDocument.Load(path);
XNamespace gml = "http://www.opengis.net/gml";
Text txt = GameObject.Find("Text").GetComponent<Text>();
//this is for unity
var query = xd.Descendants(gml + "coord")
.Select(e => new
{
X = (decimal)e.Element(gml + "X"),
Y = (decimal)e.Element(gml + "Y")
});
foreach (var c in query)
{
txt.text = c.ToString();
}
}
}
The script works perfectly with the first XML example:
<?xml version='1.0' encoding='UTF-8'?>
<schema xmlns='http://www.w3.org/2000/10/XMLSchema'
xmlns:gml='http://www.opengis.net/gml'
xmlns:xlink='http://www.w3.org/1999/xlink'
xmlns:xsi='http://www.w3.org/2000/10/XMLSchema-instance'
xsi:schemaLocation='http://www.opengis.net/gml/feature.xsd'>
<gml:Polygon srsName='http://www.opengis.net/gml/srs/epsg.xml#4283'>
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coord>
<gml:X>152.035953</gml:X>
<gml:Y>-28.2103190007845</gml:Y>
</gml:coord>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
</schema>
However, it encounters issues when trying to parse the second XML structure.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<IndoorFeatures xmlns="http://www.opengis.net/indoorgml/1.0/core"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:ns4="http://www.opengis.net/indoorgml/1.0/navigation"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
gml:id="IFs" xsi:schemaLocation="http://www.opengis.net/indoorgml/1.0/core http://schemas.opengis.net/indoorgml/1.0/indoorgmlcore.xsd">
<gml:name>IFs</gml:name>
<gml:boundedBy>
<gml:Envelope srsDimension="3" srsName="EPSG::4326">
<gml:lowerCorner>112.1168351477 48.8817891374 10.0</gml:lowerCorner>
<gml:upperCorner>116.7830482115...
If you prefer a simpler approach, consider using code like this:
var query = xd.Descendants(gml + "LinearRing").Select(
e => new
{
X = (decimal)e.Element(gml + "pos")
}
);
A question arises: how can GML be parsed effectively in C# (or JavaScript) for Unity implementation?