473,385 Members | 1,317 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,385 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?

Nov 15 '05 #1
2 1487
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?

Nov 15 '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
Nov 15 '05 #3

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

Similar topics

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...
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: ...
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...
0
by: Karel Kral | last post by:
Hello, I have created simple COM service in .NET. COM is accessed from another not NET application by late binding call. And the problem: If I call NetComClass.Hello from another .NET code, all...
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.