C# import XML file character error

I would like to query a pdb file (in XML format) and store the relevant information in another xml file.
I’ve been around some tutorials and managed to do it in simplier files.

The XML file looks like this: http://www.rcsb.org/pdb/files/1L2Y.xml

I want to store the atoms coordinates (and some other information) based in a simple condition the attribute value PDBx:auth_atom_id is equal to “N”, “CA”, or “C”.

XDocument xmlDocument = XDocument.Load (@"...ProjectC#Molecule_00PDBLibary_00DataL2Y.xml");
XDocument result = new XDocument (
                       new XElement ("Molecule",
                           new XElement ("Atom",
            from s in xmlDocument.Descendants ("PDBx:atom_site")
            where s.Attribute ("PDBx:auth_atom_id").Value == "N" // s.Attribute ("PDBx:auth_atom_id").Value == "CA" || s.Attribute ("PDBx:auth_atom_id").Value == "C"
            select new XElement ("Atom",
                    new XElement ("AtMolType", s.Element ("PDBx:auth_atom_id").Value),
                    new XElement ("CoordX", s.Element ("PDBx:Cartn_x").Value),
                    new XElement ("CoordY", s.Element ("PDBx:Cartn_y").Value),
                    new XElement ("CoordZ", s.Element ("PDBx:Cartn_z").Value)))));


When I run the script it returns a System.XML.XMLException (the character “:” can’t be used. However it’s how the XML file is constructed.
I have tried to change the character in the XML file but didn’t succeed.

Thanks in advance.

Source: xml

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.