Getting XML document string out of XmlReader

Getting XML document string out of XmlReader

Post by Lutz Roede » Tue, 06 Feb 2001 15:30:57



i wanna get the output from an XSL transformations as a text string.
the code below works fine.
however, i dont like the idea to use an XmlDocument to get the
string out of an XmlReader. since i provide nothing
more to the XmlDocument than that reader i assume it must
be possible to get the same running using XmlReader only?

XmlReader r = t.Transform(n, null);
XmlDocument i = new XmlDocument();
i.Load(r);
return i.InnerXml;

 
 
 

Getting XML document string out of XmlReader

Post by Joyce Che » Sat, 10 Feb 2001 05:26:05


Both ReadInnXml and ReadOutXml returns String.Empty if reader is not
positioned on an Element or Attribute node. The idea is you can get the
innerxml or outerxml related to an element scope. ReadOuterXml is one of the
beta2 new features.

If you just want to get the XSL transformations as a text string, you can
also use

      StringWriter sw = new StringWriter();
      XmlTextWriter    w = new XmlTextWriter(sw);
      transform.Transform(n, null, w);
      w.Flush();
      // sw.ToString() is the text string

Joyce Chen


Quote:> ReadInnerXml doesnt work at the root (before calling Read to get the
PIs) -
> what am I doing wrong?
> cant find ReadOuterXml - where have you seen this?