XPath-Navigable-Document from Nodelist

G

Guest

Hi folks,

I would like to select some nodes from a very large XML document and then
apply a stylesheet to the dom fragment / nodelist that is the result of my
XPath-Query.

I used to use MSXML where I know how to do this. In .NET I am starting to
get crazy because I don´t manage to transform my nodelist into an
XPath-Navigable-Document. Can Anybody please help me?

Thanks in advance

Martin

This is the code where maybe just one statement is missing:

XMLOutput.Clear();
XmlTextReader tr = new XmlTextReader(textBox3.Text);
XmlValidatingReader vr = new XmlValidatingReader(tr);
vr.Schemas.Add("", textBox1.Text);
vr.ValidationType = ValidationType.Schema;
vr.ValidationEventHandler += new ValidationEventHandler(MyValidationHandler);
// load document with validating reader
XmlDocument doc = new XmlDocument();
// if we get past this, we know document is valid
doc.Load(vr);
XmlNodeList list = doc.SelectNodes(Filter.Text);
label4.Text = list.Count.ToString();
//So I got my Nodelist / DOM-Fragment here in "list" now
XslTransform myXslTransform;

***** XPathDocument myXPathDocument = new XPathDocument(list); ***** //This
does not work! How to do this? *******

myXslTransform = new XslTransform();
myXslTransform.Load(textBox2.Text);

System.IO.StringWriter stWrite = new System.IO.StringWriter();
myXslTransform.Transform(myXPathDocument, null, stWrite);

XMLOutput.AppendText(stWrite.ToString());
 
M

Martin Honnen

Chucker wrote:

I would like to select some nodes from a very large XML document and then
apply a stylesheet to the dom fragment / nodelist that is the result of my
XPath-Query.

I used to use MSXML where I know how to do this. In .NET I am starting to
get crazy because I don´t manage to transform my nodelist into an
XPath-Navigable-Document. Can Anybody please help me?

This is the code where maybe just one statement is missing:

XMLOutput.Clear();
XmlTextReader tr = new XmlTextReader(textBox3.Text);
XmlValidatingReader vr = new XmlValidatingReader(tr);
vr.Schemas.Add("", textBox1.Text);
vr.ValidationType = ValidationType.Schema;
vr.ValidationEventHandler += new ValidationEventHandler(MyValidationHandler);
// load document with validating reader
XmlDocument doc = new XmlDocument();
// if we get past this, we know document is valid
doc.Load(vr);
XmlNodeList list = doc.SelectNodes(Filter.Text);
label4.Text = list.Count.ToString();
//So I got my Nodelist / DOM-Fragment here in "list" now
XslTransform myXslTransform;

***** XPathDocument myXPathDocument = new XPathDocument(list); ***** //This
does not work! How to do this? *******

myXslTransform = new XslTransform();
myXslTransform.Load(textBox2.Text);

System.IO.StringWriter stWrite = new System.IO.StringWriter();
myXslTransform.Transform(myXPathDocument, null, stWrite);

XMLOutput.AppendText(stWrite.ToString());

What are you doing with MSXML, are you applying a transformation to the
whole node list or to each node in the node list? The latter should be
possible in .NET I think, not sure about applying a transformation to a
whole node list.
Anyway, you might want to try the dotnet.xml group instead of the csharp
group.
 
G

Guest

I don´t use MSXML here! But there I would know how to make a new DOM Document
out of my node list.

The XML looks like this:

<logfile>
<logentry pid="1"/>
<logentry pid="2"/>
<logentry pid="1"/>
<logentry pid="3"/>
<logentry pid="1"/>
</logfile>

I want to select all nodes with pid="1" for example and apply a
transformation to the resulting nodes afterwards. This can be done node by
node or for the whole DOM.
 
Top