I'm trying to work out how to use Linq to XML on files which are currently structured but not strictly XML files. They are well formed files but do not contain an XML declaration. They are in fact SGML files.
At the moment i have:
private void Find_element_attribute_Click(object sender, EventArgs e)
{
if (comboBox2.Text != "")
{
string[] projectFiles = Directory.GetFiles(path, typeExtention, SearchOption.AllDirectories);
foreach (string file in projectFiles)
{
XElement root = XElement.Load(file);
IEnumerable<XElement> selectedElement = from el in root.Elements(Element_textBox.Text)
where (string)el.Attribute(Attribute_textBox.Text) == Value_textBox.Text
select el; //need to selct the DMC and title and put in a variable, and list them
foreach (XElement el in selectedElement)
MessageBox.Show("text" + el);
}
}
MessageBox.Show("Please select a project to query");
}
This throws an exeption due to a '[' character on the second line. This character is the opening bracket for a list of entities within the document.
The only way i can think to make this work is to add an XML declaration to the beginning of my documents as i open them, then query the documents using Linq, then removing the declarations. However i've no idea how to go about this. Any help appreciated.
Start of my document looks like
<!--Arbortext, Inc., 1988-2009, v.4002-->
<!DOCTYPE DMODULE PUBLIC "-//AECMA CSDB//DTD Air Vehicle Engines Equipment Description 19980102//EN" [
<!ENTITY ICN-BR8412XXXXXXX-1CX-AG30000-A-K7626-01966-A01-1 SYSTEM "ICN-BR8412XXXXXXX-1CX-AG30000-A-K7626-01966-A01-1.cgm" NDATA cgm>
<!ENTITY ICN-BR8412XXXXXXX-1CX-AG30000-A-K7626-01964-A01-1 SYSTEM "ICN-BR8412XXXXXXX-1CX-AG30000-A-K7626-01964-A01-1.cgm" NDATA cgm>
<!ENTITY ICN-BR8412XXXXXXX-1CX-AG30000-A-K7626-01963-A01-1 SYSTEM "ICN-BR8412XXXXXXX-
]>
<dmodule><idstatus>
<dmaddres>
<dmc><avee><modelic>XXXXXXAXXXXXX</modelic><sdc>1AX</sdc><chapnum>AG3</chapnum>
<section>0</section><subsect>0</subsect><subject>00</subject><discode>01</discode>
<discodev>00</discodev><incode>018</incode><incodev>A</incodev><itemloc>A
</itemloc></avee></dmc>
<dmtitle><techname>Equipment - INTRODUCTION</techname><infoname>Introduction
</infoname>
</dmtitle>
<issno issno="001" type="new">
<issdate year="2012" month="11" day="30"></dmaddres>
<status>
<security class="3">
<rpc> </rpc>
<orig> </orig>
<applic></applic>
<techstd>
<autandtp>
<authblk>Chap 1</authblk>
<tpbase>8412(A)</tpbase>
</autandtp>
<authex></authex>
<notes></notes>
</techstd>
<qa>
<firstver type="tabtop"></qa>
</status>
</idstatus><content>
<refs>
<norefs></refs>
<descript>
<para0><title>INTRODUCTION</title>