bounty457
asked on
recursiv search in a xml file
Hi Everybody,
i'm looking for a solution to read an xml file recursiv. (see attached xml file).
What i have is the "Filename", Filename = 193478618937468178.000.
Beginning from the the "Filename" i need the ID of the next node on the top.
From this ID i want to go to the next Childnode on the top, and so on.
Is there any idea how could i do this with Xpath and C# .net?
Sample:
Filename = 193478618937468178.000 --> goto ID = 2657
From
ID = 2657 --> goto ID = 1392
From
ID = 1392 --> goto ID = 8345
From
ID = 8345 --> goto ID = 1242
From
ID = 1242 --> goto ID = 39
Thank you in advance
Regards Bounty
xpath-Variant3.xml
i'm looking for a solution to read an xml file recursiv. (see attached xml file).
What i have is the "Filename", Filename = 193478618937468178.000.
Beginning from the the "Filename" i need the ID of the next node on the top.
From this ID i want to go to the next Childnode on the top, and so on.
Is there any idea how could i do this with Xpath and C# .net?
Sample:
Filename = 193478618937468178.000 --> goto ID = 2657
From
ID = 2657 --> goto ID = 1392
From
ID = 1392 --> goto ID = 8345
From
ID = 8345 --> goto ID = 1242
From
ID = 1242 --> goto ID = 39
Thank you in advance
Regards Bounty
xpath-Variant3.xml
ASKER
Thank you for the answer.
Could you please short explain how must i use the code from C#?
i want do write the data for each "filename" a one datatable after parsing the xml.
Regards Bountry
Could you please short explain how must i use the code from C#?
i want do write the data for each "filename" a one datatable after parsing the xml.
Regards Bountry
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
the sample from MSDN work right. If i change the .xsl and .xml File
i get the message:
"Leerzeichen können aus bereits geladenen Eingabedokumenten nicht entfernt werden. Stellen Sie das Eingabedokument stattdessen als XmlReader bereit."
Translate:
"Use XMLReader - Empty Spaces can't delete from the source file"
I looked at MSDN:
http://msdn.microsoft.com/en-us/library/241y3z4e.aspx
I use the XML Reader with the following code:
Das Stylesheet muss entweder mit einem 'xsl:stylesheet'- oder einem 'xsl:transform'-Element oder aber mit einem Literalergebniselement beginnen, welches das 'xsl:version'-Attribut aufweist. Dabei gibt das Präfix 'xsl' den Namespace 'http://www.w3.org/1999/XSL/Transform' an.
Translate:
"The Stylesheet must start with: xsl:stylesheet or xsl:transform element or an literal with 'xsl:version'-Attribut. The präfix must have the namespace http://www.w3.org/1999/XSL/Transform'
What must i add to the XSL File?
Regards Bounty
Variant3.xsl
the sample from MSDN work right. If i change the .xsl and .xml File
i get the message:
"Leerzeichen können aus bereits geladenen Eingabedokumenten nicht entfernt werden. Stellen Sie das Eingabedokument stattdessen als XmlReader bereit."
Translate:
"Use XMLReader - Empty Spaces can't delete from the source file"
I looked at MSDN:
http://msdn.microsoft.com/en-us/library/241y3z4e.aspx
I use the XML Reader with the following code:
// Create the XslCompiledTransform and load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
string stylesheet = "Variant3.xsl";
//Create the reader to load the stylesheet.
//Move the reader to the xsl:stylesheet node.
XmlTextReader reader = new XmlTextReader(stylesheet);
reader.Read();
reader.Read();
xslt.Load(reader);
// Create the XsltArgumentList.
XsltArgumentList argList = new XsltArgumentList();
// Add my first Filename to the Arglist
argList.AddParam("fname", "", "193478618937468178.000");
// Create an XmlWriter to write the output.
XmlWriter writer = XmlWriter.Create("Variant3_Out.xml");
// Transform the file.
xslt.Transform(new XPathDocument("xpath_Variant3.xml"), argList, writer);
writer.Close();
Now i get the Message:Das Stylesheet muss entweder mit einem 'xsl:stylesheet'- oder einem 'xsl:transform'-Element oder aber mit einem Literalergebniselement beginnen, welches das 'xsl:version'-Attribut aufweist. Dabei gibt das Präfix 'xsl' den Namespace 'http://www.w3.org/1999/XSL/Transform' an.
Translate:
"The Stylesheet must start with: xsl:stylesheet or xsl:transform element or an literal with 'xsl:version'-Attribut. The präfix must have the namespace http://www.w3.org/1999/XSL/Transform'
What must i add to the XSL File?
Regards Bounty
Variant3.xsl
apparently you have not loaded the XSLT correctly, since the above code I posted has all it needs
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
Can you check that it finds the XSLT file?
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
Can you check that it finds the XSLT file?
ASKER
Yes the File is found. The path is correct. It is a load Exception of the .xls File. It is working on your code?
I change the Variant3.xsl how you wrote.
I attached the screenshot from the error message.
Load-Exception.PNG
Variant3.xsl
I change the Variant3.xsl how you wrote.
I attached the screenshot from the error message.
Load-Exception.PNG
Variant3.xsl
You can pass in the file name as a parameter
Open in new window