473,387 Members | 3,787 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,387 software developers and data experts.

XMLDocument class parsing

I try to parse a XML document containg some references using XmlDocument
Class' method GetElementbyTagName. It just give the content between starting
tagName and ending tagName but not all refernces used between starting
tagName and ending tagName. Is there any way to achive this?

Sep 13 '05 #1
9 1859
<"=?Utf-8?B?T21rYXIgU2luZ2g=?=" <Omkar
Si***@discussions.microsoft.com>> wrote:
I try to parse a XML document containg some references using XmlDocument
Class' method GetElementbyTagName. It just give the content between starting
tagName and ending tagName but not all refernces used between starting
tagName and ending tagName. Is there any way to achive this?


It's not clear exactly what you mean. Could you give more information,
perhaps with an example XML file and preferrably a short but complete
piece of code too?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Sep 13 '05 #2
Please see the code and input file first :

In the following code, output i get is "<header href="#ref-3"/>"
but i didn't get what #ref-3 means. Actually I also wanted the content
"<Header id="ref-3" >
<title id="34">Exam title</title>
<description id="67">Exam description</description>
</Header>"
as it is part of "Exam" Node.

I wanted to use this information in different method.

File soap.txt:
<Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Body>
<Exam id="ref-1" >
<header href="#ref-3"/>
</Exam>
<Header id="ref-3" >
<title id="34">Exam title</title>
<description id="67">Exam description</description>
</Header>
</Body>
</Envelope>
Code :
public static void Main()
{
XmlDocument doc = new XmlDocument();
doc.ToString();
doc.Load("C:\\soap.txt");

//Display all the book titles.
XmlNodeList elemList = doc.GetElementsByTagName("Exam");
for (int i=0; i < elemList.Count; i++)
{
Console.WriteLine(elemList[i].InnerXml);
}

"Jon Skeet [C# MVP]" wrote:
<"=?Utf-8?B?T21rYXIgU2luZ2g=?=" <Omkar
Si***@discussions.microsoft.com>> wrote:
I try to parse a XML document containg some references using XmlDocument
Class' method GetElementbyTagName. It just give the content between starting
tagName and ending tagName but not all refernces used between starting
tagName and ending tagName. Is there any way to achive this?


It's not clear exactly what you mean. Could you give more information,
perhaps with an example XML file and preferrably a short but complete
piece of code too?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Sep 13 '05 #3
Omkar Singh <Om********@discussions.microsoft.com> wrote:
Please see the code and input file first :

In the following code, output i get is "<header href="#ref-3"/>"
but i didn't get what #ref-3 means.
Right. You've retrieved exactly what you've asked for though - the
inner piece of XML for the node.
Actually I also wanted the content
"<Header id="ref-3" >
<title id="34">Exam title</title>
<description id="67">Exam description</description>
</Header>"
as it is part of "Exam" Node.

I wanted to use this information in different method.


You'll have to use a separate way of doing that - eg by finding all
elements with an "href" attribute whose value starts with a "#", and
substituting the contents of those elements with the ones retrieved
using GetElementById with the appropriate ID.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Sep 13 '05 #4
Thanks for replying but the problem with solution you mention is I am doing
all these operation on string which is in XML format. For using
GetElementById we need Attribute define in DTD.
Is there an way to use GetElementById on string.

"Jon Skeet [C# MVP]" wrote:
Omkar Singh <Om********@discussions.microsoft.com> wrote:
Please see the code and input file first :

In the following code, output i get is "<header href="#ref-3"/>"
but i didn't get what #ref-3 means.


Right. You've retrieved exactly what you've asked for though - the
inner piece of XML for the node.
Actually I also wanted the content
"<Header id="ref-3" >
<title id="34">Exam title</title>
<description id="67">Exam description</description>
</Header>"
as it is part of "Exam" Node.

I wanted to use this information in different method.


You'll have to use a separate way of doing that - eg by finding all
elements with an "href" attribute whose value starts with a "#", and
substituting the contents of those elements with the ones retrieved
using GetElementById with the appropriate ID.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Sep 14 '05 #5
Omkar Singh <Om********@discussions.microsoft.com> wrote:
Thanks for replying but the problem with solution you mention is I am doing
all these operation on string which is in XML format. For using
GetElementById we need Attribute define in DTD.
Is there an way to use GetElementById on string.


Ah, I missed that. In that case, just use an XPath expression (and
SelectSingleNode) to find a node with the right attribute.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Sep 14 '05 #6
Thanks Jon. It is working!
Jon I hav one more problem. My string contains some namespaces(soap and
cwnp) other than default xml namespace. When I use LoadXml() method it gives
me error "'soap' is an undecleared namespace". Is there any way to overcome
this problem.
"Jon Skeet [C# MVP]" wrote:
Omkar Singh <Om********@discussions.microsoft.com> wrote:
Thanks for replying but the problem with solution you mention is I am doing
all these operation on string which is in XML format. For using
GetElementById we need Attribute define in DTD.
Is there an way to use GetElementById on string.


Ah, I missed that. In that case, just use an XPath expression (and
SelectSingleNode) to find a node with the right attribute.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Sep 15 '05 #7
Omkar Singh <Om********@discussions.microsoft.com> wrote:
Jon I hav one more problem. My string contains some namespaces(soap and
cwnp) other than default xml namespace. When I use LoadXml() method it gives
me error "'soap' is an undecleared namespace". Is there any way to overcome
this problem.


Yes - make sure your XML declares all the namespaces it uses.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Sep 15 '05 #8
Sorry Jon I didn't get it. which XML you mention. I am using string as xml
file.
Do you mean to add namespace to these string? If yes how?
"Jon Skeet [C# MVP]" wrote:
Omkar Singh <Om********@discussions.microsoft.com> wrote:
Jon I hav one more problem. My string contains some namespaces(soap and
cwnp) other than default xml namespace. When I use LoadXml() method it gives
me error "'soap' is an undecleared namespace". Is there any way to overcome
this problem.


Yes - make sure your XML declares all the namespaces it uses.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Sep 15 '05 #9
Omkar Singh <Om********@discussions.microsoft.com> wrote:
Sorry Jon I didn't get it. which XML you mention. I am using string as xml
file.
Do you mean to add namespace to these string? If yes how?


Yes - it sounds like your string isn't *really* a valid XML document.
Try to make it one, by properly declaring in it the namespaces you're
using. To be honest, I'm not very hot on XML namespaces, but I'm sure
there are good tutorials around which should help you.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 15 '05 #10

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

Similar topics

5
by: KathyB | last post by:
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an...
1
by: Martin Honnen | last post by:
With both .NET 1.0 and 1.1 I have found the following strange behaviour where System.Xml.XmlDocument.LoadXml doesn't throw an error when parsing a text node with a character reference to an invalid...
1
by: RiceGuy | last post by:
Hi, I'm wondering on how to go about writing a simple XML parser, one that doesn't use the XmlDocument class (DOM API) and relies only on (in-built, so to say low-level) file system and string...
7
by: Mark | last post by:
Hi... A colleague just referred this question to me. He's getting an xml file from another party, which he's trying to process into another dom using an XmlTextReader and...
1
by: Peter Nofelt | last post by:
Hey All, I'm running into this issue with parsing through an xml document by tag name. Below is an example xml document: File Name: things.xml <things> <people> <name>Peter</name>
4
by: David Grogan | last post by:
Hi, 2 questions.... 1. I'm parsing an XHTML document that contains both the default namespace (xmlns="http://www.w3.org/1999/xhtml") and a custom one (xmlns:r="...") - both of these being...
9
by: Omkar Singh | last post by:
I try to parse a XML document containg some references using XmlDocument Class' method GetElementbyTagName. It just give the content between starting tagName and ending tagName but not all...
2
by: Phil Galey | last post by:
I'm using the followg code to add the attribute overwrite='true" to a select list of XML tags in an XML document. The document is loaded from a file and just the tags with names matching what's in...
3
MrMancunian
by: MrMancunian | last post by:
Hi, I've created an HTTP connection with a server. I send a WebRequest in XML to the server (see strReq in code) and it returns me a WebResponse. This response is inserted in a string, which is...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.