the code:
var readerSettings = new XmlReaderSettings { ConformanceLevel = ConformanceLevel.Fragment };
using (var reader = XmlReader.Create(inputz, readerSettings))
{
while (reader.Read())
{
using (var fragmentReader = reader.ReadSubtree())
{
if (fragmentReader.Read())
{
var fragment = XNode.ReadFrom(fragmentReader) as XElement;
what its outputting:
<sys>
<id>FSB</id>
<label>FSB</label>
<value>266</value>
</sys>
<sys>
<id>CPU</id>
<label>speed</label>
<value>2930</value>
</sys>
how would i change it so that it writes "v开发者_JS百科alue" to a string instead? so the output looks like : ,266,2930
thanks
Well the obvious answer is to convert to a string -
var stringFragment = fragment.ToString();
or, if necessary,
var fragment = (XNode.ReadFrom(fragmentReader) as XElement).ToString();
I'm not 100% sure this will achieve what you're trying to do, but it will return your XML snippet as a string.
edit
Now that the question has been updated, I can give some more information. I'll assume that each fragment
is in fact the sys
node.
You first need to get the value
node, and then retrieve its 'value' (ie its content).
var valueNode = fragment.Element("value");
var content = valueNode.Value;
I would guess:
var fragment = (XNode.ReadFrom(fragmentReader)).ToString();
精彩评论