473,799 Members | 2,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XMLDocument class parsing

I try to parse a XML document containg some references using XmlDocument
Class' method GetElementbyTag Name. 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 1895
<"=?Utf-8?B?T21rYXIgU2l uZ2g=?=" <Omkar
Si***@discussio ns.microsoft.co m>> wrote:
I try to parse a XML document containg some references using XmlDocument
Class' method GetElementbyTag Name. 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.co m>
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:\\s oap.txt");

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

"Jon Skeet [C# MVP]" wrote:
<"=?Utf-8?B?T21rYXIgU2l uZ2g=?=" <Omkar
Si***@discussio ns.microsoft.co m>> wrote:
I try to parse a XML document containg some references using XmlDocument
Class' method GetElementbyTag Name. 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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Sep 13 '05 #3
Omkar Singh <Om********@dis cussions.micros oft.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.co m>
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********@dis cussions.micros oft.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Sep 14 '05 #5
Omkar Singh <Om********@dis cussions.micros oft.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
SelectSingleNod e) to find a node with the right attribute.

--
Jon Skeet - <sk***@pobox.co m>
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********@dis cussions.micros oft.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
SelectSingleNod e) to find a node with the right attribute.

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

Sep 15 '05 #7
Omkar Singh <Om********@dis cussions.micros oft.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.co m>
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********@dis cussions.micros oft.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Sep 15 '05 #9
Omkar Singh <Om********@dis cussions.micros oft.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.co m>
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
3614
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 instruction document (not data based) - same as using an xml web control. The resulting html is on the client? but what about the server side of things? Trying to figure out how to change and save the xmlDocument. It I put a button OUTSIDE of the...
1
17140
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 characters like &#x1;. Using the CreateTextNode method I create a text node containing "\u0001a" (C# string literal notation). As far as I understand the DOM allows that and an implementation is not required to throw an error. When OuterXml is...
1
1759
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 parsing functions. Are there any examples or sample code that illustrates on how to go about building a custom XML parser on these lines. The main issue is that I'm not quite sure about how to render the XML file to an in-memory data structure of...
7
4185
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 XmlDocument.ReadNode(). The problem is that it's breaking and he doesn't understand why. I didn't exactly either, which is why I'm posting a question here. First, his program just creates a new dom using new document like this: XmlDocument xml = new XmlDocument();
1
9699
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
4183
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 attributes of <html>. When I then insert new XmlNodes into the DOM the HTML tags all end up getting an unnecesarry 'xmlns' attribute added, elements with the 'r' prefix don't, which is correct. Is there any way to stop the XmlNode/XmlWriter from...
9
339
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 refernces used between starting tagName and ending tagName. Is there any way to achive this?
2
5510
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 the ArrayList are updated to contain the new attribute. However, after it saves back to the XML file, I find that only the last one in the list was updated and all the ones prior to the last one in the loop are skipped. Why is it losing the updates...
3
1538
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 then loaded into a XmlDocument. How can I parse this XmlDocument? I tried a few things, but I didn't get it to work. The output which is in de XmlDocument is like this: <?xml version="1.0" encoding="iso-8859-1" ?> <antwoord...
0
10268
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10247
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10031
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9079
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7571
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.