การแยกวิเคราะห์ที่มีน้ำหนักเบา รหัสนี้จะไม่ดาวน์โหลดข้อมูลใด ๆ จากอินเทอร์เน็ตและจะไม่เรียกใช้สคริปต์ใด ๆ แต่เป็นการแยกวิเคราะห์อย่างหมดจด
การแยกวิเคราะห์ถูกนำไปใช้ผ่าน MarkupService ของ MSHTML ในการใช้รหัสนี้อย่างถูกต้องคุณต้องเพิ่มการอ้างอิง MSHTML
เนื่องจากอินเทอร์เฟซที่ไม่น่าเชื่อไม่ได้กำหนดไว้ใน. NET จึงต้องดำเนินการด้วยตัวเองและคำจำกัดความของอินเทอร์เฟซคือ:
เนื้อหาต่อไปนี้คือรหัสโปรแกรม:
[comvisible (true), comimport (), guid ("7FD52380-4E07-101B-AE2D-08002B2EC713"
PublicInterfaceipersistStreaminit
-
voidgetClassID ([in, out] refguidpclassid);
[return: marshalas (unmanagedtype.i4)] [Preservesig]
intisdirty ();
voidload ([in, marshalas (unmanagedType.Interface)] UCOCISTREAMPSTM);
voidsave ([in, marshalas (unmanagedType.Interface)] UCOCISTREAMPSTM,
[ใน, marshalas (unmanagedtype.i4)] intfcleardirty);
VoidgetSizeMax ([OUT, Marshalas (UnmanagedType.lparray)] longpcbsize);
VoidInitNew ();
-
เนื้อหาต่อไปนี้คือรหัสโปรแกรม:
unsafeihtmldocument2parse (Strings)
-
ihtmldocument2pdocument = newhtmldocumentclass ();
if (pDocument! = null)
-
ipersistReamInitppersist = pDocumentAsipersistStreamInit;
ppsist.initnew ();
ppsist = null;
ImakupServicesms = pDocumentasimarkupServices;
ถ้า (ms! = null)
-
ImmarkUpContainerPmc = null;
imarkuppointerpstart, pend;
Ms.CreateMarkuppointer (OUTPSTART);
Ms.CreateMarkuppointer (outpend);
StringBuildersB = NewStringBuilder (S);
intptrpsource = marshal.stringtohglobaluni (s);
Ms.parsestring (Ref*(Ushort*) Psource.topointer (), 0, Outpmc, Pstart, Pend);
ถ้า (pmc! = null)
-
จอมพล. รีลีส (psource);
returnpmcasihtmldocument2;
-
จอมพล. รีลีส (psource);
-
-
returnnull;
-
มีบางอย่างผิดปกติเมื่อเขียนรหัส พารามิเตอร์แรกของ MarkupService :: Parsestring คือการคืนเงิน เห็นได้ชัดว่าการส่งผ่านในรหัส HTML ushort นี้จะต้องเป็น widechar แรกดังนั้นที่นี่เราข้ามคำเตือนคอมไพเลอร์โดยใช้รหัสที่ไม่ปลอดภัย