Jump to content

seacdsl

Members
  • Content Count

    3
  • Joined

  • Last visited

Community Reputation

0 Neutral

About seacdsl

  • Rank
    Newbie

Contact Methods

  • Website URL
    http://
  • ICQ
    0

Profile Information

  • Location
    UK
  1. Its working now! Thanks for your help.
  2. Thanks for the info, the code snippet for CreateElement is what I had been looking for. I was trying to use an XmlNode. I reckon Ive got the other element in ok, as the schema states theres a 'sequence'. Having run it through the debugger, I think I see a problem. Im not loading the schema properly as examining the value of 'schemaIn' after it does the compile reveals that it contains 0 elements, as when I come to do the AppendChild, it raises a NullReferenceException.Maybe im missing doing as you suggested, to manually create and append this element?Not quite sure. As you can probably tell im new to xml, but appreciate all the help.Heres the updated schema:<?xml version="1.0" encoding="utf-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="logResultsCT"> <xs:sequence> <xs:element name="logResults"> <xs:complexType> <xs:attribute name="value" type="xs:decimal" /> <xs:attribute name="speed" type="xs:unsignedShort" /> <xs:attribute name="time" type="xs:int" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType></xs:schema> and I can see the zero element count after the compile in this: docOut = new XmlDocument(); schemaIn = new XmlReaderSettings(); schemaIn.Schemas.Add("trySchema", "schemaFile.xsd"); schemaIn.Schemas.Compile();
  3. I have some binary data that I wish to convert to xml, using the schema as below, or something like it, but I cant see exactly how to populate the XmlDocument with my data. <?xml version="1.0" encoding="utf-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="logResults"> <xs:complexType> <xs:attribute name="value" type="xs:decimal" /> <xs:attribute name="speed" type="xs:unsignedShort" /> <xs:attribute name="time" type="xs:int" /> </xs:complexType> </xs:element></xs:schema> This is using C# in VS2005.I can create an instance of the XmlDocument and apply the schema to it, but im stumped if I can see how to populate the xmldocument using the structure predefined by the schema.The code I have so far is this: XmlReaderSettings schemaIn; XmlDocument docOut; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { docOut = new XmlDocument(); schemaIn = new XmlReaderSettings(); schemaIn.Schemas.Add("trySchema", "schemaFile.xsd"); schemaIn.Schemas.Compile(); docOut.Schemas = schemaIn.Schemas; // then what? The resulting xml should contain multiple entries of the value/speed/time element.My guess is that there would be a loop which reads my raw data, creates an element, and populates it, something like this: while (readingFile){ read(file, record); create(docOut, element); write(docOut, element , record.value); write(docOut, element , record.speed); write(docOut, element , record.time);}docOut.Save("filename"); Ive had a look at the DOM XML and Schema tutorials, but cant quite see the solution.
×
×
  • Create New...