deersuper
asked on
XML Document Loading
using System;
using System.Collections.Generic ;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MSXML2;
namespace ManipulateXML
{
public partial class Form1 : Form
{
private DOMDocument40 doc;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChan ged(object sender, EventArgs e)
{
string search = listBox1.SelectedItem.ToSt ring();
IXMLDOMNode nd = doc.selectSingleNode("book store/book [@ISBN=' " + search + " ' ]");
MessageBox.Show(nd.text);
}
private void button1_Click(object sender, EventArgs e)
{
doc = new DOMDocument40();
doc.load("books.xml");
IXMLDOMNodeList nodes;
nodes = doc.selectNodes("bookstore /book");
IXMLDOMNode node = nodes.nextNode();
while (node != null)
{
listBox1.Items.Add(node.at tributes.g etNamedIte m("ISBN"). text);
node = nodes.nextNode();
}
}
}
}
this is a pretty simple code to understand. Button click loads an XML document called books.xml and I try to get information about the ISBN of all book nodes.
I compile and it compiles but on button click nothing happens. When i ran debugger I saw that 'while (node != null ' is a false statement. Please help
using System.Collections.Generic
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MSXML2;
namespace ManipulateXML
{
public partial class Form1 : Form
{
private DOMDocument40 doc;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChan
{
string search = listBox1.SelectedItem.ToSt
IXMLDOMNode nd = doc.selectSingleNode("book
MessageBox.Show(nd.text);
}
private void button1_Click(object sender, EventArgs e)
{
doc = new DOMDocument40();
doc.load("books.xml");
IXMLDOMNodeList nodes;
nodes = doc.selectNodes("bookstore
IXMLDOMNode node = nodes.nextNode();
while (node != null)
{
listBox1.Items.Add(node.at
node = nodes.nextNode();
}
}
}
}
this is a pretty simple code to understand. Button click loads an XML document called books.xml and I try to get information about the ISBN of all book nodes.
I compile and it compiles but on button click nothing happens. When i ran debugger I saw that 'while (node != null ' is a false statement. Please help
Please paste your xml file here
And you can use System.XML instead of MSXML2 if no special purpose.
ASKER
<?xml version="1.0" encoding="utf-8" ?>
<bookstore>
<book genre="autobiography" publicationdate="1981" ISBN="1-816003-11-0">
<title>title 1</title>
<author>
<first-name>ben </first-name>
<last-name>franklin</last- name>
</author>
<price>899</price>
</book>
<book genre="novel" publicationdate="1967" ISBN="1-768503-11-0">
<title>title 2</title>
<author>
<first-name>usman </first-name>
<last-name>lakjai</last-na me>
</author>
<price>299</price>
</book>
<book genre="sex" publicationdate="1381" ISBN="1-300618-11-0">
<title>chudai</title>
<author>
<first-name>azam </first-name>
<last-name>franklin</last- name>
</author>
<price>999</price>
</book>
</bookstore>
the code book i am using specifically asks for using msxml2. thats why I used it !!!!!! thanks
<bookstore>
<book genre="autobiography" publicationdate="1981" ISBN="1-816003-11-0">
<title>title 1</title>
<author>
<first-name>ben </first-name>
<last-name>franklin</last-
</author>
<price>899</price>
</book>
<book genre="novel" publicationdate="1967" ISBN="1-768503-11-0">
<title>title 2</title>
<author>
<first-name>usman </first-name>
<last-name>lakjai</last-na
</author>
<price>299</price>
</book>
<book genre="sex" publicationdate="1381" ISBN="1-300618-11-0">
<title>chudai</title>
<author>
<first-name>azam </first-name>
<last-name>franklin</last-
</author>
<price>999</price>
</book>
</bookstore>
the code book i am using specifically asks for using msxml2. thats why I used it !!!!!! thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.