Click here to Skip to main content
15,900,714 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I have the task to display the processing-instruction values, I have tried to get the processing instruction values using XPath, XML values loaded in XDocument (XLINQ),
I am new to XLINQ, please help me.

What I have tried:

This is sample xml content

<?xml version="1.0" encoding="utf-8"?>
<document>
	<?fonts Times New Roman|Cambria Math|Symbol|Calibri|PMingLiU?>
	<body>
		<p>Para 1</p>
		<p>Para 2</p>
		<p>Para 3</p>
	</body>
</document>




I have tried below code for retrive the processing instruction content "fonts"
XProcessingInstruction pInsNode =(XProcessingInstruction) document.XPathSelectElement("processing-instruction('fonts')");
Posted
Updated 26-Dec-17 2:58am
v2

1 solution

1- create a xml file and save in your debug folder or where your application start

<xml>
    <foo>
        <baz id="1">10</baz>
        <bar id="2" special="1">baa baa</bar>
        <baz id="3">20</baz>
        <bar id="4" />
        <bar id="5" />
    </foo>
    <foo id="123">Text 1<moo />Text 2
    </foo>
</xml>



Bellow is the code for retrive the data

string fpath = Application.StartupPath + "\\" + "test.xml";
           XDocument xele = XDocument.Load(fpath);

           var node = xele.XPathSelectElement("/xml/foo[@id='123']");
           var nodes = xele.XPathSelectElements(
           "//moo/ancestor::xml/descendant::baz[@id='1']/following-sibling::bar[not(@special='1')]");
           var sum = xele.XPathEvaluate("sum(//foo[not(moo)]/baz)");




Add the bellow name spaces in your page

using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
 
Share this answer
 
Comments
smksamy 26-Dec-17 7:18am    
hello brother, I expected for retrieve Processing-instruction value.
Nakhia_ind 26-Dec-17 7:41am    
I telling that please display the total xml file.so I can run in my computer
and solve your problem
Nakhia_ind 26-Dec-17 7:38am    
sir that is a attribute of a xml tag that sir you did not provide.
I provide you every thing means xml file with code
smksamy 26-Dec-17 8:59am    
Hi friend,
i updated the sample input in question part
Nakhia_ind 26-Dec-17 9:17am    
sir Pleas send the whole xml means xml structure

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900