473,405 Members | 2,282 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,405 software developers and data experts.

XmlDocument problem

Serious problem

I'm using Chris Lovett's SgmlReader class
SgmlReader sr = new SgmlReader();
XmlDocument xdoc = new XmlDocument();
sr.DocType = "HTML";
sr.InputStream = new System.IO.StringReader(node.InnerText);
xdoc.Load(sr);
foreach(XmlNode PotentiallyMalicous in xdoc.SelectNodes("//script |
//embed //object | //frameset //frame //iframe | //meta | //link | //style |
//@style"))
{
if (node.ParentNode!=null)
PotentiallyMalicous.ParentNode.RemoveChild(Potenti allyMalicous);
else
xdoc.RemoveChild(PotentiallyMalicous);
}
item.desc = xdoc.InnerText;
Unfrotantely, I'm getting an exception on xdoc.Load(sr), saying:

System.InvalidOperationException: The specified node cannot be
inserted as the valid child of this node, because the specified node is the
wrong type.
at System.Xml.XmlDocument.AppendChildForLoad(XmlNode newChild,
XmlDocument doc)
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader,
Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at Roar.RssFeed.UpdateItem(XmlNode ItemNode, XmlNamespaceManager
nsMgr, ArrayList& NewItems, Boolean Update) in c:\documents and
settings\ayende\my documents\visual studio projects\medar\rssfeed.cs:line
233
at Roar.RssFeed.UpdateFeed(XmlDocument feed, ArrayList& NewItems,
Boolean Update)

I've no idea what is causing this.
node.InnerText equals:
<'a href="http://www.ncl.com/fleet/dawn/index.htm"><'img
src="http://monster2.scripting.com/z/images/archiveScriptingCom/2003/12/01/d
awn.jpg" width="125" height="59" border="0" align="right" hspace="15"
vspace="5" alt="A picture named dawn.jpg"><'/a>Two articles, both from the
NY Times, by coincidence happened to show up one after the other in my
aggregator, a stark contrast of how two kinds of Americans live. The first
<'a
href="http://www.nytimes.com/2003/12/01/nyregion/01SHIP.html?ex=1385614800&e
n=f12a99f582744ee2&ei=5007&partner=USERLAND">artic le<'/a> details the
luxurious cruise ship Tom DeLay is bringing to the Republican National
Convention in NYC in August, where George Bush will, presumably, be
nominated for a second term as President. It's a very beautiful ship, very
nice. The second <'a
href="http://www.nytimes.com/2003/11/27/international/worldspecial/27LIST.ht
ml?ex=1385355600&en=1fa37d9cc6c8ca0f&ei=5007&partn er=USERLAND">article<'/a>
is the daily report of US soldiers killed in Iraq. Yesterday only one
soldier died, David Goldberg, 20, an engineer in the Army reserve,
based in Layton, Utah. Needless to say he won't be going to the Republican
National Convention or riding on any cruise ships. "

Any idea what could cause it? Or how to fix it?

Jul 21 '05 #1
2 8686
I use also the SgmlReader and I've never has some problem.

I think your problem is that you need a "root" node, an XmlDocument must
have a unique starting node like:

<html>
<head>
...
</head>
<body>
...
</body>
</html>

or

<doc>
<chapter name=1>
...
</chapter>
<chapter name=2>
...
</chapter>
</doc>

The stucture of your document is:
<a ..><img .../> </a>
<#text>
<a ..></a>
<#text>
<a ..></a>
<#text>

If it's so try the following:

new System.IO.StringReader("<p>"+node.InnerText+"</p>");

"Ayende Rahien" <Ay****@no.spam> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP09.phx.gbl...
Serious problem

I'm using Chris Lovett's SgmlReader class
SgmlReader sr = new SgmlReader();
XmlDocument xdoc = new XmlDocument();
sr.DocType = "HTML";
sr.InputStream = new System.IO.StringReader(node.InnerText);
xdoc.Load(sr);
foreach(XmlNode PotentiallyMalicous in xdoc.SelectNodes("//script |
//embed //object | //frameset //frame //iframe | //meta | //link | //style | //@style"))
{
if (node.ParentNode!=null)
PotentiallyMalicous.ParentNode.RemoveChild(Potenti allyMalicous);
else
xdoc.RemoveChild(PotentiallyMalicous);
}
item.desc = xdoc.InnerText;
Unfrotantely, I'm getting an exception on xdoc.Load(sr), saying:

System.InvalidOperationException: The specified node cannot be
inserted as the valid child of this node, because the specified node is the wrong type.
at System.Xml.XmlDocument.AppendChildForLoad(XmlNode newChild,
XmlDocument doc)
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader,
Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at Roar.RssFeed.UpdateItem(XmlNode ItemNode, XmlNamespaceManager
nsMgr, ArrayList& NewItems, Boolean Update) in c:\documents and
settings\ayende\my documents\visual studio projects\medar\rssfeed.cs:line
233
at Roar.RssFeed.UpdateFeed(XmlDocument feed, ArrayList& NewItems,
Boolean Update)

I've no idea what is causing this.
node.InnerText equals:
<'a href="http://www.ncl.com/fleet/dawn/index.htm"><'img
src="http://monster2.scripting.com/z/images/archiveScriptingCom/2003/12/01/d awn.jpg" width="125" height="59" border="0" align="right" hspace="15"
vspace="5" alt="A picture named dawn.jpg"><'/a>Two articles, both from the
NY Times, by coincidence happened to show up one after the other in my
aggregator, a stark contrast of how two kinds of Americans live. The first
<'a
href="http://www.nytimes.com/2003/12/01/nyregion/01SHIP.html?ex=1385614800&e n=f12a99f582744ee2&ei=5007&partner=USERLAND">artic le<'/a> details the
luxurious cruise ship Tom DeLay is bringing to the Republican National
Convention in NYC in August, where George Bush will, presumably, be
nominated for a second term as President. It's a very beautiful ship, very
nice. The second <'a
href="http://www.nytimes.com/2003/11/27/international/worldspecial/27LIST.ht ml?ex=1385355600&en=1fa37d9cc6c8ca0f&ei=5007&partn er=USERLAND">article<'/a> is the daily report of US soldiers killed in Iraq. Yesterday only one
soldier died, David Goldberg, 20, an engineer in the Army reserve,
based in Layton, Utah. Needless to say he won't be going to the Republican
National Convention or riding on any cruise ships. "

Any idea what could cause it? Or how to fix it?

Jul 21 '05 #2

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:uV**************@TK2MSFTNGP12.phx.gbl...
I use also the SgmlReader and I've never has some problem.
Try
new System.IO.StringReader("<p>"+node.InnerText+"</p>");


Dude!
It works!
Thanks a Lot
Jul 21 '05 #3

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

Similar topics

4
by: Robert Rossney | last post by:
I'm trying to send and receive XmlDocument objects using the System.Messaging.dll functions. The code I've written follows, as best I can tell, the methodology used in the sample code for the...
1
by: Shawn | last post by:
Hi. I'm using a FileStream (instead of just the path to the xml file) to load an XmlDocument. I'm doing this because I need to be able to prevent other processes to update the file I'm working on....
7
by: SQLScott | last post by:
I have a Web Service in which I am trying to pass an XMLDocument as a parameter to one of the methods. I would like to use the XMLTextReader to read the XML but I am getting the following error: ...
2
by: Ayende Rahien | last post by:
Serious problem I'm using Chris Lovett's SgmlReader class SgmlReader sr = new SgmlReader(); XmlDocument xdoc = new XmlDocument(); sr.DocType = "HTML"; sr.InputStream = new...
3
by: Mungo Jerrie | last post by:
Hi there :-) I have some problems with the same instance of my xmldocument across 3 different classes. See code below: class one { protected static XmlDocument doc = new XmlDocument(); ...
1
by: itsme | last post by:
Hello, How can one copy an XmlDocument "A" into another XmlDocument "B" When I say "copy", I mean to replace the XmlDocument "A" completely by the XmlDocument "B". I am trying to use...
1
by: Joe Monnin | last post by:
I have a web service that takes an XmlDocument as a parameter, performs some processing on it, and saves it to a database. The web service signature looks similar to this: public void...
14
by: jens Jensen | last post by:
Hello, I'm calling a webmethod from a webservice written in java. I need to pass an xml file as parameter to the webmethod. I therefore use System.Xml.XmlDocument to load the xml file. The...
3
by: Stephen Ward | last post by:
I have a simple little project open a xml file change a few nodes save the file, no big deal. The problem is that the doctype is getting modified when I save the file. So it looks like this:...
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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...
0
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...
0
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,...
0
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...

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.