473,322 Members | 1,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Parsing XML within XML

I need to parse an XML file and print the contents of it on an aspx page. My
XML file structure is like this:

<QueryResult>
<messageNo>1</messageNo>
<messageText />
<HERE>
<ExternalIntegrator><Entities>
<name>John</name>
<surname>Carpenter</surname>
<age>47</age>
</Entities></ExternalIntegrator>
</HERE>
<status>statusFound</status>
</QueryResult>

What I want to do is to get the data within "HERE" tags first. Then, I need
to parse this xml and get the name, surname etc. I mean, I need to parse the
xml document within the xml document.
I am trying to do it using XmlTextReader but when I use it second time (for
inner xml) I get the error PathTooLongException.

How can I parse this XML within XML and get the NAME value?

PS: What I basically do->
....
XmlTextReader reader = null;
reader = new XmlTextReader(UrlToXmlFile);
object oMyTag = reader.NameTable.Add("HERE");
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name.Equals(oMyTag))
{
return ReadXML2(reader.ReadString()); // here I want to do the same
thing for inner xml but get the error :(
}
....
Nov 16 '05 #1
8 1899
hi
here is the code
use Dom Parsing

XmlDocument objDoc=new XmlDocument();
objDoc.Load("a.Xml");
XmlNode objNode;
objNode= objDoc.SelectSingleNode("//QueryResult/HERE");
MessageBox .Show(objNode.InnerXml );

XmlNode objSecNode;
objSecNode= objNode.SelectSingleNode("ExternalIntegrator/Entities");
MessageBox .Show(objSecNode.InnerXml );

MessageBox.Show(objSecNode.ChildNodes[0].InnerText);
MessageBox.Show(objSecNode.ChildNodes[1].InnerText);
MessageBox.Show(objSecNode.ChildNodes[2].InnerText);

objDoc=null;

regards
ansil

"Dinçer" <dincer"AT" wrote:
I need to parse an XML file and print the contents of it on an aspx page. My
XML file structure is like this:

<QueryResult>
<messageNo>1</messageNo>
<messageText />
<HERE>
<ExternalIntegrator><Entities>
<name>John</name>
<surname>Carpenter</surname>
<age>47</age>
</Entities></ExternalIntegrator>
</HERE>
<status>statusFound</status>
</QueryResult>

What I want to do is to get the data within "HERE" tags first. Then, I need
to parse this xml and get the name, surname etc. I mean, I need to parse the
xml document within the xml document.
I am trying to do it using XmlTextReader but when I use it second time (for
inner xml) I get the error PathTooLongException.

How can I parse this XML within XML and get the NAME value?

PS: What I basically do->
....
XmlTextReader reader = null;
reader = new XmlTextReader(UrlToXmlFile);
object oMyTag = reader.NameTable.Add("HERE");
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name.Equals(oMyTag))
{
return ReadXML2(reader.ReadString()); // here I want to do the same
thing for inner xml but get the error :(
}
....

Nov 16 '05 #2
Thank you for the answer.
But I got the error when I use objDoc.SelectSingleNode(\\QueryResult\\xml):
'\QueryResult\xml' has an invalid token.

Where am I doing wrong?

"Ansil MCAD" <An*******@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.com...
hi
here is the code
use Dom Parsing

XmlDocument objDoc=new XmlDocument();
objDoc.Load("a.Xml");
XmlNode objNode;
objNode= objDoc.SelectSingleNode("//QueryResult/HERE");
MessageBox .Show(objNode.InnerXml );

XmlNode objSecNode;
objSecNode= objNode.SelectSingleNode("ExternalIntegrator/Entities");
MessageBox .Show(objSecNode.InnerXml );

MessageBox.Show(objSecNode.ChildNodes[0].InnerText);
MessageBox.Show(objSecNode.ChildNodes[1].InnerText);
MessageBox.Show(objSecNode.ChildNodes[2].InnerText);

objDoc=null;

regards
ansil

"Dinçer" <dincer"AT" wrote:
I need to parse an XML file and print the contents of it on an aspx page. My XML file structure is like this:

<QueryResult>
<messageNo>1</messageNo>
<messageText />
<HERE>
<ExternalIntegrator><Entities>
<name>John</name>
<surname>Carpenter</surname>
<age>47</age>
</Entities></ExternalIntegrator>
</HERE>
<status>statusFound</status>
</QueryResult>

What I want to do is to get the data within "HERE" tags first. Then, I need to parse this xml and get the name, surname etc. I mean, I need to parse the xml document within the xml document.
I am trying to do it using XmlTextReader but when I use it second time (for inner xml) I get the error PathTooLongException.

How can I parse this XML within XML and get the NAME value?

PS: What I basically do->
....
XmlTextReader reader = null;
reader = new XmlTextReader(UrlToXmlFile);
object oMyTag = reader.NameTable.Add("HERE");
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name.Equals(oMyTag))
{
return ReadXML2(reader.ReadString()); // here I want to do the same thing for inner xml but get the error :(
}
....

Nov 16 '05 #3
Oops.. Ignoe my question please..

\ vs. /

:-)
"Dinçer" <dincer"AT"o2.pl> wrote in message
news:ul**************@TK2MSFTNGP12.phx.gbl...
Thank you for the answer.
But I got the error when I use objDoc.SelectSingleNode(\\QueryResult\\xml): '\QueryResult\xml' has an invalid token.

Where am I doing wrong?

"Ansil MCAD" <An*******@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.com...
hi
here is the code
use Dom Parsing

XmlDocument objDoc=new XmlDocument();
objDoc.Load("a.Xml");
XmlNode objNode;
objNode= objDoc.SelectSingleNode("//QueryResult/HERE");
MessageBox .Show(objNode.InnerXml );

XmlNode objSecNode;
objSecNode= objNode.SelectSingleNode("ExternalIntegrator/Entities");
MessageBox .Show(objSecNode.InnerXml );

MessageBox.Show(objSecNode.ChildNodes[0].InnerText);
MessageBox.Show(objSecNode.ChildNodes[1].InnerText);
MessageBox.Show(objSecNode.ChildNodes[2].InnerText);

objDoc=null;

regards
ansil

"Dinçer" <dincer"AT" wrote:
I need to parse an XML file and print the contents of it on an aspx page. My XML file structure is like this:

<QueryResult>
<messageNo>1</messageNo>
<messageText />
<HERE>
<ExternalIntegrator><Entities>
<name>John</name>
<surname>Carpenter</surname>
<age>47</age>
</Entities></ExternalIntegrator>
</HERE>
<status>statusFound</status>
</QueryResult>

What I want to do is to get the data within "HERE" tags first. Then, I need to parse this xml and get the name, surname etc. I mean, I need to
parse
the xml document within the xml document.
I am trying to do it using XmlTextReader but when I use it second time (for inner xml) I get the error PathTooLongException.

How can I parse this XML within XML and get the NAME value?

PS: What I basically do->
....
XmlTextReader reader = null;
reader = new XmlTextReader(UrlToXmlFile);
object oMyTag = reader.NameTable.Add("HERE");
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name.Equals(oMyTag))
{
return ReadXML2(reader.ReadString()); // here I want to do
the
same thing for inner xml but get the error :(
}
....


Nov 16 '05 #4
I tried it again but when executing this line:
"objSecNode.InnerXml "
it gets the error:
"Object reference not set to an instance of an object. "

Why could that happen?
"Ansil MCAD" <An*******@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.com...
hi
here is the code
use Dom Parsing

XmlDocument objDoc=new XmlDocument();
objDoc.Load("a.Xml");
XmlNode objNode;
objNode= objDoc.SelectSingleNode("//QueryResult/HERE");
MessageBox .Show(objNode.InnerXml );

XmlNode objSecNode;
objSecNode= objNode.SelectSingleNode("ExternalIntegrator/Entities");
MessageBox .Show(objSecNode.InnerXml );

MessageBox.Show(objSecNode.ChildNodes[0].InnerText);
MessageBox.Show(objSecNode.ChildNodes[1].InnerText);
MessageBox.Show(objSecNode.ChildNodes[2].InnerText);

objDoc=null;

regards
ansil

"Dinçer" <dincer"AT" wrote:
I need to parse an XML file and print the contents of it on an aspx page. My XML file structure is like this:

<QueryResult>
<messageNo>1</messageNo>
<messageText />
<HERE>
<ExternalIntegrator><Entities>
<name>John</name>
<surname>Carpenter</surname>
<age>47</age>
</Entities></ExternalIntegrator>
</HERE>
<status>statusFound</status>
</QueryResult>

What I want to do is to get the data within "HERE" tags first. Then, I need to parse this xml and get the name, surname etc. I mean, I need to parse the xml document within the xml document.
I am trying to do it using XmlTextReader but when I use it second time (for inner xml) I get the error PathTooLongException.

How can I parse this XML within XML and get the NAME value?

PS: What I basically do->
....
XmlTextReader reader = null;
reader = new XmlTextReader(UrlToXmlFile);
object oMyTag = reader.NameTable.Add("HERE");
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name.Equals(oMyTag))
{
return ReadXML2(reader.ReadString()); // here I want to do the same thing for inner xml but get the error :(
}
....

Nov 16 '05 #5
The queries Ansil specified are correct, perhaps your code doesn't
exactly match since there were syntax errors in the post. Are you sure
the second SelectSingleNode method call happens on the node found from
the previous call?

XmlDocument doc = new XmlDocument();
doc.Load(filename);
XmlNode hereNode = doc.SelectSingleNode("//QueryResult/HERE");
Console.WriteLine(hereNode.InnerXml);

XmlNode entityNode =
hereNode.SelectSingleNode("ExternalIntegrator/Entities");
Console.WriteLine(entityNode.InnerXml );

Console.WriteLine(entityNode.ChildNodes[0].InnerText);
Console.WriteLine(entityNode.ChildNodes[1].InnerText);
Console.WriteLine(entityNode.ChildNodes[2].InnerText);

--
Scott
http://www.OdeToCode.com/
On Mon, 11 Oct 2004 17:10:11 +0300, "Dinçer" <dincer"AT"o2.pl> wrote:
I tried it again but when executing this line:
"objSecNode.InnerXml "
it gets the error:
"Object reference not set to an instance of an object. "

Why could that happen?


Nov 16 '05 #6
Actually, I go to a URL first which returns me the main XML.
Main XML:
<?xml version="1.0" encoding="windows-1254" ?>
- <QueryResult>
<messageNo>1</messageNo>
<messageText />

<xml><ExternalIntegrator><Entities><Entity><Fields ><NAME>JOHN</NAME><MIDDLE_
NAME
/><SURNAME>COOLER</SURNAME></Fields></Entity></Entities></ExternalIntegrator
</xml> <status>statusFound</status>
</QueryResult>

So, I use:

objDoc = new XmlDocument();
objDoc.Load(new XmlTextReader(myURL));
XmlNode objNode;
objNode = objDoc.SelectSingleNode("//QueryResult/xml");
XmlNode objSecNode;
objSecNode =
objNode.SelectSingleNode("ExternalIntegrator/Entities/Entity/Fields");
Response.Write(objSecNode.InnerXml);
Response.Write("\n<b>"+objSecNode.ChildNodes[0].InnerText);

However, I got the error:
"Object reference not set to an instance of an object. "

Do I miss anything?
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:kp********************************@4ax.com... The queries Ansil specified are correct, perhaps your code doesn't
exactly match since there were syntax errors in the post. Are you sure
the second SelectSingleNode method call happens on the node found from
the previous call?

XmlDocument doc = new XmlDocument();
doc.Load(filename);
XmlNode hereNode = doc.SelectSingleNode("//QueryResult/HERE");
Console.WriteLine(hereNode.InnerXml);

XmlNode entityNode =
hereNode.SelectSingleNode("ExternalIntegrator/Entities");
Console.WriteLine(entityNode.InnerXml );

Console.WriteLine(entityNode.ChildNodes[0].InnerText);
Console.WriteLine(entityNode.ChildNodes[1].InnerText);
Console.WriteLine(entityNode.ChildNodes[2].InnerText);

--
Scott
http://www.OdeToCode.com/
On Mon, 11 Oct 2004 17:10:11 +0300, "Dinçer" <dincer"AT"o2.pl> wrote:
I tried it again but when executing this line:
"objSecNode.InnerXml "
it gets the error:
"Object reference not set to an instance of an object. "

Why could that happen?

Nov 16 '05 #7
BTW, innerXML value of objDoc.SelectSingleNode("//QueryResult/xml")
returns:
&lt;ExternalIntegrator&gt;&lt;Entities&gt;&lt;Enti ty
instead of
<ExternalIntegrator><Entities><Entity...

Could that be the problem?
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:kp********************************@4ax.com...
The queries Ansil specified are correct, perhaps your code doesn't
exactly match since there were syntax errors in the post. Are you sure
the second SelectSingleNode method call happens on the node found from
the previous call?

XmlDocument doc = new XmlDocument();
doc.Load(filename);
XmlNode hereNode = doc.SelectSingleNode("//QueryResult/HERE");
Console.WriteLine(hereNode.InnerXml);

XmlNode entityNode =
hereNode.SelectSingleNode("ExternalIntegrator/Entities");
Console.WriteLine(entityNode.InnerXml );

Console.WriteLine(entityNode.ChildNodes[0].InnerText);
Console.WriteLine(entityNode.ChildNodes[1].InnerText);
Console.WriteLine(entityNode.ChildNodes[2].InnerText);

--
Scott
http://www.OdeToCode.com/
On Mon, 11 Oct 2004 17:10:11 +0300, "Dinçer" <dincer"AT"o2.pl> wrote:
I tried it again but when executing this line:
"objSecNode.InnerXml "
it gets the error:
"Object reference not set to an instance of an object. "

Why could that happen?

Nov 16 '05 #8
hi
this following code is working fine in my PC

XmlDocument objDoc=new XmlDocument();
objDoc.Load("a.Xml");
XmlNode objNode;
objNode= objDoc.SelectSingleNode("//QueryResult/xml");
MessageBox .Show(objNode.InnerXml );

XmlNode objSecNode;
objSecNode=
objNode.SelectSingleNode("ExternalIntegrator/Entities/Entity/Fields");
MessageBox .Show(objSecNode.InnerXml );
MessageBox.Show(objSecNode.ChildNodes[0].InnerText);
MessageBox.Show(objSecNode.ChildNodes[1].InnerText);
MessageBox.Show(objSecNode.ChildNodes[2].InnerText);

objDoc=null;

take care that the xpath expression in the SelectSingleNode mehtod is case
sensitive.i think thats the problem with u

regards
ansil

"Dinçer" <dincer"AT" wrote:
Actually, I go to a URL first which returns me the main XML.
Main XML:
<?xml version="1.0" encoding="windows-1254" ?>
- <QueryResult>
<messageNo>1</messageNo>
<messageText />

<xml><ExternalIntegrator><Entities><Entity><Fields ><NAME>JOHN</NAME><MIDDLE_
NAME
/><SURNAME>COOLER</SURNAME></Fields></Entity></Entities></ExternalIntegrator
</xml>

<status>statusFound</status>
</QueryResult>

So, I use:

objDoc = new XmlDocument();
objDoc.Load(new XmlTextReader(myURL));
XmlNode objNode;
objNode = objDoc.SelectSingleNode("//QueryResult/xml");
XmlNode objSecNode;
objSecNode =
objNode.SelectSingleNode("ExternalIntegrator/Entities/Entity/Fields");
Response.Write(objSecNode.InnerXml);
Response.Write("\n<b>"+objSecNode.ChildNodes[0].InnerText);

However, I got the error:
"Object reference not set to an instance of an object. "

Do I miss anything?
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:kp********************************@4ax.com...
The queries Ansil specified are correct, perhaps your code doesn't
exactly match since there were syntax errors in the post. Are you sure
the second SelectSingleNode method call happens on the node found from
the previous call?

XmlDocument doc = new XmlDocument();
doc.Load(filename);
XmlNode hereNode = doc.SelectSingleNode("//QueryResult/HERE");
Console.WriteLine(hereNode.InnerXml);

XmlNode entityNode =
hereNode.SelectSingleNode("ExternalIntegrator/Entities");
Console.WriteLine(entityNode.InnerXml );

Console.WriteLine(entityNode.ChildNodes[0].InnerText);
Console.WriteLine(entityNode.ChildNodes[1].InnerText);
Console.WriteLine(entityNode.ChildNodes[2].InnerText);

--
Scott
http://www.OdeToCode.com/
On Mon, 11 Oct 2004 17:10:11 +0300, "Dinçer" <dincer"AT"o2.pl> wrote:
I tried it again but when executing this line:
"objSecNode.InnerXml "
it gets the error:
"Object reference not set to an instance of an object. "

Why could that happen?


Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Jean de Largentaye | last post by:
Hi, I need to parse a subset of C (a header file), and generate some unit tests for the functions listed in it. I thus need to parse the code, then rewrite function calls with wrong parameters....
4
by: ralphNOSPAM | last post by:
Is there a function or otherwise some way to pull out the target text within an XML tag? For example, in the XML tag below, I want to pull out 'CALIFORNIA'. ...
1
by: Steve | last post by:
Hi, I am new to XML and PHP and have a question that I hope someone could answer. Some background on my problem. I am receiving an XML message over TCP/IP and need to access data within the...
6
by: Computer_Czar | last post by:
I'm trying to figure out the best way to parse an input string from a file for hex values. The string is actually Motorola S code produced by an embedded assembler. For example lines contain...
3
by: Pir8 | last post by:
I have a complex xml file, which contains stories within a magazine. The structure of the xml file is as follows: <?xml version="1.0" encoding="ISO-8859-1" ?> <magazine> <story>...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
4
by: Neil.Smith | last post by:
I can't seem to find any references to this, but here goes: In there anyway to parse an html/aspx file within an asp.net application to gather a collection of controls in the file. For instance...
9
by: Paulers | last post by:
Hello, I have a log file that contains many multi-line messages. What is the best approach to take for extracting data out of each message and populating object properties to be stored in an...
7
by: Donn Ingle | last post by:
Hi, I really hope someone can help me -- I'm stuck. I have written three versions of code over a week and still can't get past this problem, it's blocking my path to getting other code written. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.