【发布时间】:2017-11-04 01:45:08
【问题描述】:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Xml;
public class XmlReader : MonoBehaviour
{
XmlDocument doc = new XmlDocument();
// Use this for initialization
void Start ()
{
doc.Load(@"C:\Users\myxml\Documents\mysvg.svg");
XmlNode node = doc.DocumentElement.SelectSingleNode("/g");
foreach (XmlNode nodes in doc.DocumentElement.ChildNodes)
{
string text = nodes.InnerText; //or loop through its children as well
}
}
// Update is called once per frame
void Update ()
{
}
}
我想得到<g>下的所有孩子
然后将每个孩子解析为数组,例如:
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<rect
style="opacity:1;fill:#00c8fc;fill-opacity:0.98823529;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rect4155"
width="45.714287"
height="30"
x="37.387959"
y="115.30345" />
<rect
style="opacity:1;fill:#00c8fc;fill-opacity:0.98823529;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rect4155-5"
width="45.714287"
height="30"
x="91.899246"
y="115.40621" />
所以我想创建数组调用它Rects
也许string[] Rects;
然后在数组中的每个 Rect 下将他的参数也作为字符串:
Rect1
fill:#00c8fc
width="45.714287"
height="30"
x="37.387959"
y="115.30345"
这种格式。
然后我可以从另一个脚本访问 Rect1 和他的参数,例如:
Rect1.width... 或 Rect1.x....Rect1.fill....
【问题讨论】:
-
不是 svg html 而不是 xml?
-
答案是,您可以像解析任何其他 XML 文件一样解析它。这里有几十个类似的问题。
标签: c# xml svg xml-parsing