Ask a Question related to ASP.NET Web Services, Design and Development.
-
Smile #1
extracting an entire node from XML file
i have a file which i have to write in C#. i want to extract an entire
node by itself at once ( wherever it occurs in the file .. as )
<?xml version="1.0"?>
<book>
<person>
<first>Kiran</first>
<last>Pai</last>
<age>22</age>
</person>
<person>
<first>Bill</first>
<last>Gates</last>
<age>46</age>
</person>
<person>
<first>Steve</first>
<last>Jobs</last>
<age>40</age>
</person>
</book>
Program Output
Root element of the doc is book
Total no of people : 3
First Name : Kiran
Last Name : Pai
Age : 22
First Name : Bill
Last Name : Gates
Age : 46
First Name : Steve
Last Name : Jobs
Age : 40
In java it says something like ...
DocumentBuilderFactory docBuilderFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse (new File("book.xml"));
// normalize text representation
doc.getDocumentElement ().normalize ();
System.out.println ("Root element of the doc is " +
doc.getDocumentElement().getNodeName());
NodeList listOfPersons = doc.getElementsByTagName("person");
int totalPersons = listOfPersons.getLength();
System.out.println("Total no of people : " + totalPersons);
for(int s=0; s<listOfPersons.getLength() ; s++){
Node firstPersonNode = listOfPersons.item(s);
if(firstPersonNode.getNodeType() == Node.ELEMENT_NODE){
Element firstPersonElement = (Element)firstPersonNode;
...........
....
Here in the same place of NodeList and all that .. what do i use in C#.
is there anything with the same functionality
??
Please someone out there help me on this.
Smile
*** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
Don't just participate in USENET...get rewarded for it!
Smile Guest
-
Can't I insert an entire XML node?
I'm trying to insert an entire XML node - it completely matches the other nodes in the XML Doc. But CF just gives me errors (An error occured while... -
Extracting an img file
How do i extract the contents of an img file so i can view // empty the contents out? without burning due to it being a 3.1gig img file and i got... -
#25729 [Opn->Bgs]: $node->get_content() returns the entire content of all descendant nodes
ID: 25729 Updated by: rrichards@php.net Reported By: fabiostt at libero dot it -Status: Open +Status: ... -
#25729 [NEW]: $node->get_content() returns the entire content of all descendant nodes
From: fabiostt at libero dot it Operating system: any PHP version: 4.3.3 PHP Bug Type: DOM XML related Bug description: ... -
[PHP] Value for entire file
> -----Original Message----- No, $_GET has always been superglobal, it just didn't exist before 4.1.0 -- so for PHP <4.1.0 it's: function... -
Dominic Hopton #2
Re: extracting an entire node from XML file
You should be able to use a similar method in C# - just look in the
..net SDK docs at accessing XML files using the XmlDocument Interface.
You may want to look at my RssEater sample
([url]http://www.codevoid.net/downloads.htm[/url] . In this sample I load an XML
document (RSS in this case) into an XMLDocument and then get the notes
out, almost exactly like your java code, except in c#.
If this is not what you are asking, could you provide a few more
details?
Yours,
Dominic
On Wed, 08 Oct 2003 23:25:15 -0700, Smile <smiley@developersdex.com>
wrote:
>i have a file which i have to write in C#. i want to extract an entire
>node by itself at once ( wherever it occurs in the file .. as )
>
><?xml version="1.0"?>
><book>
><person>
><first>Kiran</first>
><last>Pai</last>
><age>22</age>
></person>
><person>
><first>Bill</first>
><last>Gates</last>
><age>46</age>
></person>
><person>
><first>Steve</first>
><last>Jobs</last>
><age>40</age>
></person>
></book>
>
>Program Output
>Root element of the doc is book
>Total no of people : 3
>First Name : Kiran
>Last Name : Pai
>Age : 22
>First Name : Bill
>Last Name : Gates
>Age : 46
>First Name : Steve
>Last Name : Jobs
>Age : 40
>
>
>In java it says something like ...
>DocumentBuilderFactory docBuilderFactory =
>DocumentBuilderFactory.newInstance();
>DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
>Document doc = docBuilder.parse (new File("book.xml"));
>
>// normalize text representation
>doc.getDocumentElement ().normalize ();
>System.out.println ("Root element of the doc is " +
>doc.getDocumentElement().getNodeName());
>
>
>NodeList listOfPersons = doc.getElementsByTagName("person");
>int totalPersons = listOfPersons.getLength();
>System.out.println("Total no of people : " + totalPersons);
>for(int s=0; s<listOfPersons.getLength() ; s++){
>
>
>Node firstPersonNode = listOfPersons.item(s);
>if(firstPersonNode.getNodeType() == Node.ELEMENT_NODE){
>
>
>Element firstPersonElement = (Element)firstPersonNode;
>
>..........
>...
>
>Here in the same place of NodeList and all that .. what do i use in C#.
>is there anything with the same functionality
>??
>
>Please someone out there help me on this.
>
>Smile
>
>
>*** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
>Don't just participate in USENET...get rewarded for it!Dominic Hopton Guest



Reply With Quote

