本文整理汇总了C#中XmlTextReader.ReadSubtree方法的典型用法代码示例。如果您正苦于以下问题:C# XmlTextReader.ReadSubtree方法的具体用法?C# XmlTextReader.ReadSubtree怎么用?C# XmlTextReader.ReadSubtree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlTextReader
的用法示例。
在下文中一共展示了XmlTextReader.ReadSubtree方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
// Use this for initialization
public static void Load () {
using(XmlTextReader reader = new XmlTextReader("strijps"))
// using (XmlReader reader = XmlReader.Create("Assets/Maps/andorra"))
{
while (reader.Read())
{
// Only detect start elements.
if (reader.IsStartElement())
{
//Debug.Log (reader.Name);
// Get element name and switch on it.
switch (reader.Name)
{
case "osm":
// Detect this element.
break;
case "bounds":
break;
case "node":
long nodeId = long.Parse (reader ["id"]);
float lat = float.Parse (reader ["lat"]);
float lon = float.Parse (reader ["lon"]);
List<OsmTag> nodeTags = new List<OsmTag> ();
XmlReader nodeSubtree = reader.ReadSubtree ();
readNodeSubtree (nodeSubtree, nodeTags);
OsmNode node = new OsmNode (nodeId, nodeTags, lon, lat);
Data.Instance.nodes.Add (nodeId, node);
break;
case "tag":
break;
case "member":
break;
case "nd":
break;
case "way":
long wayId = long.Parse (reader ["id"]);
List<OsmTag> wayTags = new List<OsmTag> ();
List<OsmNodeReference> wayNodes = new List<OsmNodeReference> ();
XmlReader waySubtree = reader.ReadSubtree ();
readWaySubtree (waySubtree, wayNodes, wayTags);
OsmWay way = new OsmWay (wayId, wayTags, wayNodes);
foreach (OsmTag tag in wayTags) {
if (tag.getKey () == "building") {
Data.Instance.buildings.Add (wayId, new OsmBuilding (wayId, wayTags, wayNodes));
}
if (tag.getKey () == "highway") {
Data.Instance.streets.Add (wayId, new OsmStreet (wayId, wayTags, wayNodes));
}
if (tag.getKey () == "landuse" || tag.getKey() == "natural" ){ //|| tag.getKey() == "surface") {
if (!Data.Instance.surfaces.ContainsKey(wayId))
Data.Instance.surfaces.Add (wayId, new OsmSurface (wayId, wayTags, wayNodes, tag.getValue()));
}
}
Data.Instance.ways.Add(wayId, way);
break;
case "relation":
long relationId = long.Parse (reader ["id"]);
List<OsmRelationMember> members = new List<OsmRelationMember> ();
List<OsmTag> relationTags = new List<OsmTag> ();
XmlReader relationSubtree = reader.ReadSubtree ();
readRelationSubtree (relationSubtree, members, relationTags);
OsmRelation relation = new OsmRelation (relationId, relationTags, members);
Data.Instance.relations.Add(relationId, relation);
break;
default:
Debug.Log (reader.Name);
break;
}
}
}
}
foreach(long key in Data.Instance.ways.Keys)
{
OsmWay w = (OsmWay) Data.Instance.ways[key];
for(int i = 0; i < w.getNumberOfNodes(); i++) {
OsmNodeReference nodeRef = w.getNodeReference (i);
if (!Data.Instance.nodes.ContainsKey (nodeRef.getId ()))
continue;
OsmNode n = (OsmNode) Data.Instance.nodes [nodeRef.getId()];
n.addContainedIn (w);
nodeRef.setLattitudeAndLongitude (n.getLatitude (), n.getLongitude ());
}
}
Debug.Log ("Nodes: " + Data.Instance.nodes.Count);
Debug.Log ("Ways: " + Data.Instance.ways.Count);
Debug.Log ("Relations: " + Data.Instance.relations.Count);
Debug.Log("Buildings: " + Data.Instance.buildings.Count);
Debug.Log("Streets: " + Data.Instance.streets.Count);
Debug.Log ("Done");
Data.Instance.dataLoaded = true;
}
示例2: xmlparse
// pseudo SAX reader
public static void xmlparse(string fname)
{
XmlReader reader = new XmlTextReader(fname);
string line;
urls = new ArrayList();
int cnt = 0;
// http://msdn.microsoft.com/en-us/library/1z92b1d4.aspx
// http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.readsubtree.aspx
while (reader.Read()) {
if (reader.MoveToContent() == XmlNodeType.Element &&
reader.Name == "formvals") {
XmlReader inner = reader.ReadSubtree();
StringDictionary myCol = new StringDictionary();
while (inner.Read()) {
if (inner.MoveToContent() == XmlNodeType.Element &&
inner.Name == "input") {
inner.MoveToFirstAttribute();
// to avoid dependency on the attribute order, key them by the attribute name
// amended with the unique count of the current input element.
myCol.Add(String.Format("{0}-{1}", inner.Name, cnt.ToString()), inner.Value);
inner.MoveToNextAttribute();
myCol.Add(String.Format("{0}-{1}", inner.Name, cnt.ToString()), inner.Value);
cnt++;
}
DictionaryEntry[] myArr = new DictionaryEntry[myCol.Count];
myCol.CopyTo(myArr, 0);
for (int i = 0; i < myArr.Length; i++) {
try{
string inputNameRegExp = @"name\-(?<input>\d+)";
MatchCollection myMatchCollection =
Regex.Matches(myArr[i].Key.ToString(), inputNameRegExp );
foreach (Match myMatch in myMatchCollection) {
string pos = myMatch.Groups["input"].Value.ToString();
// do not use StringDictionary for final formvals or you have your keyc converted to lower case.
formvals.Add(myCol[String.Format("name-{0}", pos)], myCol[String.Format("value-{0}", pos)]);
}
} catch (Exception e) {
Console.WriteLine(e.ToString());
}
}
myCol.Clear();
}
foreach ( KeyValuePair<string, string> kvp in formvals )
Console.WriteLine("formvals[ {0} ] = {1}", kvp.Key, kvp.Value);
inner.Close();
}
if (reader.MoveToContent() == XmlNodeType.Element && reader.Name == "url") {
line = reader.ReadString();
urls.Add(line);
Console.WriteLine(line);
}
}
}