tags:

views:

103

answers:

1

Hi, I would like log my keyboad strokes in a xml file. The attribute can be the key, and the value can be the timestamps or the other way ( doesn't matter). I would like to write the schema in the way that my output of schema would be exactly like this:

<LoggingActions>
  <Keyboad>
       <Entry key="a">0</Entry>
       <Entry key="b">1213</Entry>
       <Entry key="c">3445</Entry>
  </Keyboad>
</LoggingActions>

so far, this is my schema:

<xs:element name="MyEvents">
  <xs:complexType>
    <xs:sequence>
      <xs:element ref="LoggingActions"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

<xs:element name="KeyboardEvent">
  <xs:complexType>
    <xs:sequence>
      <xs:element ref="MyKeyEntry"/>
      <xs:element ref="Time"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

<xs:element name="MyKeyEntry">
  <xs:complexType>
    <xs:sequence>
      <xs:element maxOccurs="unbounded"  ref="keyReference"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

<xs:element name="Time">
  <xs:complexType>
    <xs:sequence>
      <xs:element maxOccurs="unbounded"  ref="timeRef"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

<xs:element name="keyReference" type="xs:string"/>
<xs:element name="timeRef" type="xs:int"/>

Instead, I am getting this xml as my output:

<LoggingActionsxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
<LoggedKey>
    <MyKeyEntry>a</MyKeyEntry> 
    <MyKeyEntry>b</MyKeyEntry> 
    <MyKeyEntry>c</MyKeyEntry> 
  </LoggedKey>

  <Time>
    <timeRef>0</timeRef> 
    <timeRef>1213</timeRef> 
    <timeRef>3445</timeRef> 
  </Time>
  </LoggingActions>

How can I combine these two together?

thanks,

+2  A: 

The desired XML is not in a valid format, your "Entry" notes should have some attribute, probably something like 'value="a"' instead of just '="a"', though it is easy enough to infer your intent.

<LoggingActions>
   <Keyboard>
     <Entry value="a">0</Entry>
     <Entry value="b">1213</Entry>
     <Entry value="c">3445</Entry>
   </Keyboard>
</LoggingActions>

The subsequen schema would look like this:

<?xml version="1.0" encoding="utf-16"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  <xsd:element name="LoggingActions" type="LoggingActionsType" />
  <xsd:complexType name="LoggingActionsType">
    <xsd:sequence>
      <xsd:element name="Keyboard" type="KeyboardType" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="KeyboardType">
    <xsd:sequence>
      <xsd:element maxOccurs="unbounded" name="Entry" type="EntryType" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="EntryType">
    <xsd:attribute name="value" type="xsd:string" />
  </xsd:complexType>
</xsd:schema>
James Conigliaro
Thanks for the schema. If I want to generate an object based on this schema, and set my key/value to those object. It can <PRE>LoggingActionsType loggingAction = new LoggingActionsType();loggingAction.Keyboard. <?>It has a SetValue method but this does not work.loggingAction.Keyboard.SetValue(keyboard.ToString(), GetTimestamp());</PRE>