我有這樣的變化之後基本SVG文檔1個flowtext和1個文本元素:如何從xml結構訪問子元素?
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="744.09448819"
height="1052.3622047"
id="svg2"
version="1.1"
inkscape:version="0.48.2 r9819"
sodipodi:docname="New document 1">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.35"
inkscape:cx="375"
inkscape:cy="520"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1366"
inkscape:window-height="706"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<flowRoot
xml:space="preserve"
id="flowRoot2985"
style="fill:black;stroke:none;stroke-opacity:1;stroke-width:1px;stroke-linejoin:miter;stroke-linecap:butt;fill-opacity:1;font-family:Arial;font-style:normal;font-weight:normal;font-size:40px;line-height:125%;letter-spacing:0px;word-spacing:0px;-inkscape-font-specification:Arial;font-stretch:normal;font-variant:normal;text-anchor:middle;text-align:center;writing-mode:lr">
<flowRegion
id="flowRegion2987">
<rect
id="rect2989"
width="600"
height="162.85715"
x="97.14286"
y="89.505043"
style="-inkscape-font-specification:Arial;font-family:Arial;font-weight:normal;font-style:normal;font-stretch:normal;font-variant:normal;font-size:40px;text-anchor:middle;text-align:center;writing-mode:lr;line-height:125%" />
</flowRegion>
<flowPara
id="flowPara2993">Yahoo</flowPara>
</flowRoot>
<text
xml:space="preserve"
style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
x="197.14285"
y="352.36218"
id="text3003"
sodipodi:linespacing="125%">
<tspan
sodipodi:role="line"
id="tspan3005"
x="197.14285"
y="352.36218">Gmail</tspan>
</text>
</g>
</svg>
我只是想這是g
元素中(.IE flowRoot & text
)的元素,
此我想:
XElement svg = XElement.Load("path to svg file");
IEnumerable<XElement> elements = svg.Element("g").Elements();
但是,這是行不通的。請幫我嗎?
嘗試使用後代,而不是元素。 – 2012-07-12 10:02:50
是的,我嘗試過'svg.Descendants(「g」)。後代();'但它給出了null – 2012-07-12 10:05:13
感謝所有回答我的問題的人,但任何人都可以告訴我我錯在哪裏,爲什麼這些' 「Decendants」方法在這裏不起作用? – 2012-07-12 10:16:13