SgmlReader problem...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ayende Rahien

    #1

    SgmlReader problem...

    I've a mysterious problem using SgmlReader, I get an exception doing to
    following code:

    I get the following exception calling CleanHtml("Pain less software
    management");

    "System.Argumen tNullException: Value cannot be null.
    Parameter name: stream
    at System.IO.Strea mReader..ctor(S tream stream, Encoding encoding, Boolean
    detectEncodingF romByteOrderMar ks, Int32 bufferSize)
    at System.IO.Strea mReader..ctor(S tream stream)
    at Sgml.SgmlReader .LazyLoadDtd(Ur i baseUri)
    at Sgml.SgmlReader .Read()
    at System.Xml.XmlL oader.Load(XmlD ocument doc, XmlReader reader, Boolean
    preserveWhitesp ace)
    at System.Xml.XmlD ocument.Load(Xm lReader reader)
    at Roar.RoarCache. CleanHtml(Strin g Html) in f:\vs.net
    projects\roar\r oarcache.cs:lin e 528"




    private static string CleanHtml(strin g Html)
    {
    Sgml.SgmlReader sr = new Sgml.SgmlReader ();
    XmlDocument xdoc = new XmlDocument();
    sr.DocType = "HTML";
    sr.InputStream = new System.IO.Strin gReader("<p>"+H tml+"</p>");
    xdoc.Load(sr);
    foreach(XmlNode PotentiallyMali cous in
    xdoc.SelectNode s("//@[local-name()='style'] |
    //@*[starts-with(local-name(),'on')] | //*[local-name()='script' or
    local-name()='object' or local-name()='embed' or local-name()='iframe' or
    local-name()='meta' or local-name()='frame'o r local-name()='framese t' or
    local-name()='link' or local-name()='style']"))
    {
    if(PotentiallyM alicous.NodeTyp e == XmlNodeType.Att ribute)
    {
    XmlAttribute PotentiallyMali cousAttribute = PotentiallyMali cous as
    XmlAttribute;

    PotentiallyMali cousAttribute.O wnerElement.Att ributes.Remove( PotentiallyMali c
    ousAttribute);
    }
    else
    //No need to check for PotentiallyMali cous.ParentNode == null because I
    added the <p></p> when composing it
    PotentiallyMali cous.ParentNode .RemoveChild(Po tentiallyMalico us);
    }
    return xdoc.InnerXml;
    }



  • Colin Savage

    #2
    Re: SgmlReader problem...

    Without the code for SgmlReader...it 's anyone's guess what the problem is.
    My guess is you are passing a null stream to this method
    System.IO.Strea mReader..ctor because the uri passed to
    Sgml.SgmlReader .LazyLoadDtd(Ur i baseUri) is invalid or null or cannot be
    resolved

    Colin

    "Ayende Rahien" <Ayende@no.spam > wrote in message
    news:OyCMiS8vDH A.2452@tk2msftn gp13.phx.gbl...[color=blue]
    > I've a mysterious problem using SgmlReader, I get an exception doing to
    > following code:
    >
    > I get the following exception calling CleanHtml("Pain less software
    > management");
    >
    > "System.Argumen tNullException: Value cannot be null.
    > Parameter name: stream
    > at System.IO.Strea mReader..ctor(S tream stream, Encoding encoding,[/color]
    Boolean[color=blue]
    > detectEncodingF romByteOrderMar ks, Int32 bufferSize)
    > at System.IO.Strea mReader..ctor(S tream stream)
    > at Sgml.SgmlReader .LazyLoadDtd(Ur i baseUri)
    > at Sgml.SgmlReader .Read()
    > at System.Xml.XmlL oader.Load(XmlD ocument doc, XmlReader reader, Boolean
    > preserveWhitesp ace)
    > at System.Xml.XmlD ocument.Load(Xm lReader reader)
    > at Roar.RoarCache. CleanHtml(Strin g Html) in f:\vs.net
    > projects\roar\r oarcache.cs:lin e 528"
    >
    >
    >
    >
    > private static string CleanHtml(strin g Html)
    > {
    > Sgml.SgmlReader sr = new Sgml.SgmlReader ();
    > XmlDocument xdoc = new XmlDocument();
    > sr.DocType = "HTML";
    > sr.InputStream = new System.IO.Strin gReader("<p>"+H tml+"</p>");
    > xdoc.Load(sr);
    > foreach(XmlNode PotentiallyMali cous in
    > xdoc.SelectNode s("//@[local-name()='style'] |
    > //@*[starts-with(local-name(),'on')] | //*[local-name()='script' or
    > local-name()='object' or local-name()='embed' or local-name()='iframe' or
    > local-name()='meta' or local-name()='frame'o r local-name()='framese t' or
    > local-name()='link' or local-name()='style']"))
    > {
    > if(PotentiallyM alicous.NodeTyp e == XmlNodeType.Att ribute)
    > {
    > XmlAttribute PotentiallyMali cousAttribute = PotentiallyMali cous as
    > XmlAttribute;
    >
    >[/color]
    PotentiallyMali cousAttribute.O wnerElement.Att ributes.Remove( PotentiallyMali c[color=blue]
    > ousAttribute);
    > }
    > else
    > //No need to check for PotentiallyMali cous.ParentNode == null because[/color]
    I[color=blue]
    > added the <p></p> when composing it
    > PotentiallyMali cous.ParentNode .RemoveChild(Po tentiallyMalico us);
    > }
    > return xdoc.InnerXml;
    > }
    >
    >
    >[/color]


    Comment

    • Ayende Rahien

      #3
      Re: SgmlReader problem...

      I found the problem, apperantly I compiled without embedding a resource,
      which caused SgmlReader to output this message.

      "Colin Savage" <sav912@hotmail .com> wrote in message
      news:br9c9q$pcl $1@ctb-nnrp2.saix.net. ..[color=blue]
      > Without the code for SgmlReader...it 's anyone's guess what the problem is.
      > My guess is you are passing a null stream to this method
      > System.IO.Strea mReader..ctor because the uri passed to
      > Sgml.SgmlReader .LazyLoadDtd(Ur i baseUri) is invalid or null or cannot be
      > resolved
      >
      > Colin
      >
      > "Ayende Rahien" <Ayende@no.spam > wrote in message
      > news:OyCMiS8vDH A.2452@tk2msftn gp13.phx.gbl...[color=green]
      > > I've a mysterious problem using SgmlReader, I get an exception doing to
      > > following code:
      > >
      > > I get the following exception calling CleanHtml("Pain less software
      > > management");
      > >
      > > "System.Argumen tNullException: Value cannot be null.
      > > Parameter name: stream
      > > at System.IO.Strea mReader..ctor(S tream stream, Encoding encoding,[/color]
      > Boolean[color=green]
      > > detectEncodingF romByteOrderMar ks, Int32 bufferSize)
      > > at System.IO.Strea mReader..ctor(S tream stream)
      > > at Sgml.SgmlReader .LazyLoadDtd(Ur i baseUri)
      > > at Sgml.SgmlReader .Read()
      > > at System.Xml.XmlL oader.Load(XmlD ocument doc, XmlReader reader,[/color][/color]
      Boolean[color=blue][color=green]
      > > preserveWhitesp ace)
      > > at System.Xml.XmlD ocument.Load(Xm lReader reader)
      > > at Roar.RoarCache. CleanHtml(Strin g Html) in f:\vs.net
      > > projects\roar\r oarcache.cs:lin e 528"
      > >
      > >
      > >
      > >
      > > private static string CleanHtml(strin g Html)
      > > {
      > > Sgml.SgmlReader sr = new Sgml.SgmlReader ();
      > > XmlDocument xdoc = new XmlDocument();
      > > sr.DocType = "HTML";
      > > sr.InputStream = new System.IO.Strin gReader("<p>"+H tml+"</p>");
      > > xdoc.Load(sr);
      > > foreach(XmlNode PotentiallyMali cous in
      > > xdoc.SelectNode s("//@[local-name()='style'] |
      > > //@*[starts-with(local-name(),'on')] | //*[local-name()='script' or
      > > local-name()='object' or local-name()='embed' or local-name()='iframe' or
      > > local-name()='meta' or local-name()='frame'o r local-name()='framese t' or
      > > local-name()='link' or local-name()='style']"))
      > > {
      > > if(PotentiallyM alicous.NodeTyp e == XmlNodeType.Att ribute)
      > > {
      > > XmlAttribute PotentiallyMali cousAttribute = PotentiallyMali cous as
      > > XmlAttribute;
      > >
      > >[/color]
      >[/color]
      PotentiallyMali cousAttribute.O wnerElement.Att ributes.Remove( PotentiallyMali c[color=blue][color=green]
      > > ousAttribute);
      > > }
      > > else
      > > //No need to check for PotentiallyMali cous.ParentNode == null[/color][/color]
      because[color=blue]
      > I[color=green]
      > > added the <p></p> when composing it
      > > PotentiallyMali cous.ParentNode .RemoveChild(Po tentiallyMalico us);
      > > }
      > > return xdoc.InnerXml;
      > > }
      > >
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...