문제

I need to append Html element after an existing element in CsQuery, for example:

I've this code

        CQ frgt = CQ.CreateFragment("<p>some text</p>");
        CQ html = CQ.CreateFromFile("index.html");

        // I also tried .Append instead of After
        string x = html.Select("#test").After(frgt).Render();

index.html content:

 <!DOCTYPE html>
 <html>
     <head>
         <meta charset="utf-8" />
         <title></title>
     </head>
     <body>
         <div id="page">
             <div class="test">
                    <p>test</p>
                 </div>
         </div>
     </body>
 </html>

The rendered string doesn't contain the 'frgt' content! What am I missing here?

Thanks

도움이 되었습니까?

해결책

The selector #test in this line:

string x = html.Select("#test").After(frgt).Render();

is looking for an element with id="test". Your HTML only has an element with class test. Probably you want:

string x = html.Select(".test").After(frgt).Render();

.. to select the node with class test.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top