Cannot Create a DataSet from Signed XML Document

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have XML Documents that I am digitally signing, and need to be able to load
these documents into DataSet objects. However, after checking the signature
and using the DataSet.ReadXML method, I am getting an exception "The root
element is missing".

I have struggled over the last 24 hours trying to figure out ways of
correcting this, however I am stuck. I would appreciate any help that the
community can provide me on this.

Thanks,
 
Here is an example of the file. The file is used to create 3 datatables in
the DataSet, I used the signature information in the first node position and
the last node. This example shows the signature in the first position using
the XmlDocument.DocumentElement.PrependChild() method.

Thanks

<?xml version="1.0" encoding="utf-8"?>
<FWT>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod
Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="">
<Transforms>
<Transform
Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<DigestValue>hxyhMOAfdFJYOsDlADHTah0Gmmg=</DigestValue>
</Reference>
</SignedInfo>

<SignatureValue>rakRKha0vAX8cIsFwhJUsgzOB1NMNW6viG/EsTUivy4Rt3Cg2k1LDTkmJv+bXhgWBoPBtdMxg9ZSXah0P1qw5K/1npSWPmJ9uWGEQuWwZT5KqJNfq1iy7QKfUiKGTn1q+0Mc2WXPo18v6Fnuqqh7+btrpfnvbTaKJ0mQHAw9H+0=</SignatureValue>
<KeyInfo>
<KeyValue xmlns="http://www.w3.org/2000/09/xmldsig#">
<RSAKeyValue>

<Modulus>01k61JX5bc/jCLnnEHtzw3o08hs6+KjE58md8wkRrBgTTEU3gtmD1Q8SxPxpJiSwGNRCWTAghxSrK7AFYOCGZTblstnHerqs0Z/LTVNW2JaVkI34kvquqWdd6JJ+GNYWWuKuTiTjyEpLSikjXXFTWkLJqDU/w1Lq6MN6g+z6lx8=</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
</KeyValue>
</KeyInfo>
</Signature>
<FWT_CONFIG>
<keyName>#PEREXEMPAMT</keyName>
<keyValue>3100</keyValue>
</FWT_CONFIG>
<FWT_FORMULA>
<Step>1</Step>
<Token>MUL</Token>
<Arg1>@TAXWAGES</Arg1>
<Arg2>@PAYPERIODS</Arg2>
<Arg3>ANNUALWAGE</Arg3>
<Arg4 />
<Arg5 />
<Arg6 />
<Arg7 />
<Arg8 />
<DefValue>0</DefValue>
<Comment />
</FWT_FORMULA>
<FWT_TAXTABLES>
<filingStatus>1</filingStatus>
<taxTableId>3</taxTableId>
<baseWage>9700</baseWage>
<upperWage>30800</upperWage>
<taxAmt>705</taxAmt>
<taxRate>0.15</taxRate>
</FWT_TAXTABLES>
<FWT_TAXTABLES>
<filingStatus>1</filingStatus>
<taxTableId>4</taxTableId>
<baseWage>30800</baseWage>
<upperWage>68500</upperWage>
<taxAmt>3870</taxAmt>
<taxRate>0.25</taxRate>
</FWT_TAXTABLES>
</FWT>


Nicholas Paldino said:
Brian,

Can you post an example of the signed document?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Brian W. Smith said:
I have XML Documents that I am digitally signing, and need to be able to
load
these documents into DataSet objects. However, after checking the
signature
and using the DataSet.ReadXML method, I am getting an exception "The root
element is missing".

I have struggled over the last 24 hours trying to figure out ways of
correcting this, however I am stuck. I would appreciate any help that the
community can provide me on this.

Thanks,
 
Brian,

I saved that XML document to a file, and then loaded it into a DataSet
without any problems. Are you sure this is the right file, and how are you
loading it into the DataSet?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Brian W. Smith said:
Here is an example of the file. The file is used to create 3 datatables in
the DataSet, I used the signature information in the first node position
and
the last node. This example shows the signature in the first position
using
the XmlDocument.DocumentElement.PrependChild() method.

Thanks

<?xml version="1.0" encoding="utf-8"?>
<FWT>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod
Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="">
<Transforms>
<Transform
Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<DigestValue>hxyhMOAfdFJYOsDlADHTah0Gmmg=</DigestValue>
</Reference>
</SignedInfo>

<SignatureValue>rakRKha0vAX8cIsFwhJUsgzOB1NMNW6viG/EsTUivy4Rt3Cg2k1LDTkmJv+bXhgWBoPBtdMxg9ZSXah0P1qw5K/1npSWPmJ9uWGEQuWwZT5KqJNfq1iy7QKfUiKGTn1q+0Mc2WXPo18v6Fnuqqh7+btrpfnvbTaKJ0mQHAw9H+0=</SignatureValue>
<KeyInfo>
<KeyValue xmlns="http://www.w3.org/2000/09/xmldsig#">
<RSAKeyValue>

<Modulus>01k61JX5bc/jCLnnEHtzw3o08hs6+KjE58md8wkRrBgTTEU3gtmD1Q8SxPxpJiSwGNRCWTAghxSrK7AFYOCGZTblstnHerqs0Z/LTVNW2JaVkI34kvquqWdd6JJ+GNYWWuKuTiTjyEpLSikjXXFTWkLJqDU/w1Lq6MN6g+z6lx8=</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
</KeyValue>
</KeyInfo>
</Signature>
<FWT_CONFIG>
<keyName>#PEREXEMPAMT</keyName>
<keyValue>3100</keyValue>
</FWT_CONFIG>
<FWT_FORMULA>
<Step>1</Step>
<Token>MUL</Token>
<Arg1>@TAXWAGES</Arg1>
<Arg2>@PAYPERIODS</Arg2>
<Arg3>ANNUALWAGE</Arg3>
<Arg4 />
<Arg5 />
<Arg6 />
<Arg7 />
<Arg8 />
<DefValue>0</DefValue>
<Comment />
</FWT_FORMULA>
<FWT_TAXTABLES>
<filingStatus>1</filingStatus>
<taxTableId>3</taxTableId>
<baseWage>9700</baseWage>
<upperWage>30800</upperWage>
<taxAmt>705</taxAmt>
<taxRate>0.15</taxRate>
</FWT_TAXTABLES>
<FWT_TAXTABLES>
<filingStatus>1</filingStatus>
<taxTableId>4</taxTableId>
<baseWage>30800</baseWage>
<upperWage>68500</upperWage>
<taxAmt>3870</taxAmt>
<taxRate>0.25</taxRate>
</FWT_TAXTABLES>
</FWT>


Nicholas Paldino said:
Brian,

Can you post an example of the signed document?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Brian W. Smith said:
I have XML Documents that I am digitally signing, and need to be able to
load
these documents into DataSet objects. However, after checking the
signature
and using the DataSet.ReadXML method, I am getting an exception "The
root
element is missing".

I have struggled over the last 24 hours trying to figure out ways of
correcting this, however I am stuck. I would appreciate any help that
the
community can provide me on this.

Thanks,
 
Thanks for the quick reply. I am passing it in as a StreamReader, as I am
using the same StreamReader to pull out the signature and verify it. Below is
the code that i am using.

sr is the StreamReader that contains the file


XmlDocument doc = new XmlDocument();

doc.Load(sr);
SignedXml verifier = new SignedXml(doc);
verifier.LoadXml(doc.GetElementsByTagName("Signature")[0] as XmlElement);

if (verifier.CheckSignature())
{

this.GetConfigFileToScreen(sr);
}


public void GetConfigFileToScreen ( StreamReader sr )
{
DataSet ds1 = new DataSet();
ds1.ReadXml(sr); // This is the error line.


Nicholas Paldino said:
Brian,

I saved that XML document to a file, and then loaded it into a DataSet
without any problems. Are you sure this is the right file, and how are you
loading it into the DataSet?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Brian W. Smith said:
Here is an example of the file. The file is used to create 3 datatables in
the DataSet, I used the signature information in the first node position
and
the last node. This example shows the signature in the first position
using
the XmlDocument.DocumentElement.PrependChild() method.

Thanks

<?xml version="1.0" encoding="utf-8"?>
<FWT>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod
Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="">
<Transforms>
<Transform
Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<DigestValue>hxyhMOAfdFJYOsDlADHTah0Gmmg=</DigestValue>
</Reference>
</SignedInfo>

<SignatureValue>rakRKha0vAX8cIsFwhJUsgzOB1NMNW6viG/EsTUivy4Rt3Cg2k1LDTkmJv+bXhgWBoPBtdMxg9ZSXah0P1qw5K/1npSWPmJ9uWGEQuWwZT5KqJNfq1iy7QKfUiKGTn1q+0Mc2WXPo18v6Fnuqqh7+btrpfnvbTaKJ0mQHAw9H+0=</SignatureValue>
<KeyInfo>
<KeyValue xmlns="http://www.w3.org/2000/09/xmldsig#">
<RSAKeyValue>

<Modulus>01k61JX5bc/jCLnnEHtzw3o08hs6+KjE58md8wkRrBgTTEU3gtmD1Q8SxPxpJiSwGNRCWTAghxSrK7AFYOCGZTblstnHerqs0Z/LTVNW2JaVkI34kvquqWdd6JJ+GNYWWuKuTiTjyEpLSikjXXFTWkLJqDU/w1Lq6MN6g+z6lx8=</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
</KeyValue>
</KeyInfo>
</Signature>
<FWT_CONFIG>
<keyName>#PEREXEMPAMT</keyName>
<keyValue>3100</keyValue>
</FWT_CONFIG>
<FWT_FORMULA>
<Step>1</Step>
<Token>MUL</Token>
<Arg1>@TAXWAGES</Arg1>
<Arg2>@PAYPERIODS</Arg2>
<Arg3>ANNUALWAGE</Arg3>
<Arg4 />
<Arg5 />
<Arg6 />
<Arg7 />
<Arg8 />
<DefValue>0</DefValue>
<Comment />
</FWT_FORMULA>
<FWT_TAXTABLES>
<filingStatus>1</filingStatus>
<taxTableId>3</taxTableId>
<baseWage>9700</baseWage>
<upperWage>30800</upperWage>
<taxAmt>705</taxAmt>
<taxRate>0.15</taxRate>
</FWT_TAXTABLES>
<FWT_TAXTABLES>
<filingStatus>1</filingStatus>
<taxTableId>4</taxTableId>
<baseWage>30800</baseWage>
<upperWage>68500</upperWage>
<taxAmt>3870</taxAmt>
<taxRate>0.25</taxRate>
</FWT_TAXTABLES>
</FWT>


Nicholas Paldino said:
Brian,

Can you post an example of the signed document?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have XML Documents that I am digitally signing, and need to be able to
load
these documents into DataSet objects. However, after checking the
signature
and using the DataSet.ReadXML method, I am getting an exception "The
root
element is missing".

I have struggled over the last 24 hours trying to figure out ways of
correcting this, however I am stuck. I would appreciate any help that
the
community can provide me on this.

Thanks,
 
Brian,

You are reading from the stream, but you are not resetting the position,
it would seem. You basically want to do this before you read the data set:

// Set the position to the beginning.
sr.BaseStream.Position = 0;

// Discard buffered data.
sr.DiscardBufferedData();

// Read normally.

That should work.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Brian W. Smith said:
Thanks for the quick reply. I am passing it in as a StreamReader, as I am
using the same StreamReader to pull out the signature and verify it. Below
is
the code that i am using.

sr is the StreamReader that contains the file


XmlDocument doc = new XmlDocument();

doc.Load(sr);
SignedXml verifier = new SignedXml(doc);
verifier.LoadXml(doc.GetElementsByTagName("Signature")[0] as XmlElement);

if (verifier.CheckSignature())
{

this.GetConfigFileToScreen(sr);
}


public void GetConfigFileToScreen ( StreamReader sr )
{
DataSet ds1 = new DataSet();
ds1.ReadXml(sr); // This is the error line.


Nicholas Paldino said:
Brian,

I saved that XML document to a file, and then loaded it into a
DataSet
without any problems. Are you sure this is the right file, and how are
you
loading it into the DataSet?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Brian W. Smith said:
Here is an example of the file. The file is used to create 3 datatables
in
the DataSet, I used the signature information in the first node
position
and
the last node. This example shows the signature in the first position
using
the XmlDocument.DocumentElement.PrependChild() method.

Thanks

<?xml version="1.0" encoding="utf-8"?>
<FWT>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod
Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="">
<Transforms>
<Transform
Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"
/>
<DigestValue>hxyhMOAfdFJYOsDlADHTah0Gmmg=</DigestValue>
</Reference>
</SignedInfo>

<SignatureValue>rakRKha0vAX8cIsFwhJUsgzOB1NMNW6viG/EsTUivy4Rt3Cg2k1LDTkmJv+bXhgWBoPBtdMxg9ZSXah0P1qw5K/1npSWPmJ9uWGEQuWwZT5KqJNfq1iy7QKfUiKGTn1q+0Mc2WXPo18v6Fnuqqh7+btrpfnvbTaKJ0mQHAw9H+0=</SignatureValue>
<KeyInfo>
<KeyValue xmlns="http://www.w3.org/2000/09/xmldsig#">
<RSAKeyValue>

<Modulus>01k61JX5bc/jCLnnEHtzw3o08hs6+KjE58md8wkRrBgTTEU3gtmD1Q8SxPxpJiSwGNRCWTAghxSrK7AFYOCGZTblstnHerqs0Z/LTVNW2JaVkI34kvquqWdd6JJ+GNYWWuKuTiTjyEpLSikjXXFTWkLJqDU/w1Lq6MN6g+z6lx8=</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
</KeyValue>
</KeyInfo>
</Signature>
<FWT_CONFIG>
<keyName>#PEREXEMPAMT</keyName>
<keyValue>3100</keyValue>
</FWT_CONFIG>
<FWT_FORMULA>
<Step>1</Step>
<Token>MUL</Token>
<Arg1>@TAXWAGES</Arg1>
<Arg2>@PAYPERIODS</Arg2>
<Arg3>ANNUALWAGE</Arg3>
<Arg4 />
<Arg5 />
<Arg6 />
<Arg7 />
<Arg8 />
<DefValue>0</DefValue>
<Comment />
</FWT_FORMULA>
<FWT_TAXTABLES>
<filingStatus>1</filingStatus>
<taxTableId>3</taxTableId>
<baseWage>9700</baseWage>
<upperWage>30800</upperWage>
<taxAmt>705</taxAmt>
<taxRate>0.15</taxRate>
</FWT_TAXTABLES>
<FWT_TAXTABLES>
<filingStatus>1</filingStatus>
<taxTableId>4</taxTableId>
<baseWage>30800</baseWage>
<upperWage>68500</upperWage>
<taxAmt>3870</taxAmt>
<taxRate>0.25</taxRate>
</FWT_TAXTABLES>
</FWT>


:

Brian,

Can you post an example of the signed document?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

message
I have XML Documents that I am digitally signing, and need to be able
to
load
these documents into DataSet objects. However, after checking the
signature
and using the DataSet.ReadXML method, I am getting an exception "The
root
element is missing".

I have struggled over the last 24 hours trying to figure out ways of
correcting this, however I am stuck. I would appreciate any help
that
the
community can provide me on this.

Thanks,
 
Thanks again, I implemented your solution, however I am still receiving the
same exception. Any ideas? I appreciate your looking into this for me.

Nicholas Paldino said:
Brian,

You are reading from the stream, but you are not resetting the position,
it would seem. You basically want to do this before you read the data set:

// Set the position to the beginning.
sr.BaseStream.Position = 0;

// Discard buffered data.
sr.DiscardBufferedData();

// Read normally.

That should work.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Brian W. Smith said:
Thanks for the quick reply. I am passing it in as a StreamReader, as I am
using the same StreamReader to pull out the signature and verify it. Below
is
the code that i am using.

sr is the StreamReader that contains the file


XmlDocument doc = new XmlDocument();

doc.Load(sr);
SignedXml verifier = new SignedXml(doc);
verifier.LoadXml(doc.GetElementsByTagName("Signature")[0] as XmlElement);

if (verifier.CheckSignature())
{

this.GetConfigFileToScreen(sr);
}


public void GetConfigFileToScreen ( StreamReader sr )
{
DataSet ds1 = new DataSet();
ds1.ReadXml(sr); // This is the error line.


Nicholas Paldino said:
Brian,

I saved that XML document to a file, and then loaded it into a
DataSet
without any problems. Are you sure this is the right file, and how are
you
loading it into the DataSet?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Here is an example of the file. The file is used to create 3 datatables
in
the DataSet, I used the signature information in the first node
position
and
the last node. This example shows the signature in the first position
using
the XmlDocument.DocumentElement.PrependChild() method.

Thanks

<?xml version="1.0" encoding="utf-8"?>
<FWT>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod
Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="">
<Transforms>
<Transform
Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"
/>
<DigestValue>hxyhMOAfdFJYOsDlADHTah0Gmmg=</DigestValue>
</Reference>
</SignedInfo>

<SignatureValue>rakRKha0vAX8cIsFwhJUsgzOB1NMNW6viG/EsTUivy4Rt3Cg2k1LDTkmJv+bXhgWBoPBtdMxg9ZSXah0P1qw5K/1npSWPmJ9uWGEQuWwZT5KqJNfq1iy7QKfUiKGTn1q+0Mc2WXPo18v6Fnuqqh7+btrpfnvbTaKJ0mQHAw9H+0=</SignatureValue>
<KeyInfo>
<KeyValue xmlns="http://www.w3.org/2000/09/xmldsig#">
<RSAKeyValue>

<Modulus>01k61JX5bc/jCLnnEHtzw3o08hs6+KjE58md8wkRrBgTTEU3gtmD1Q8SxPxpJiSwGNRCWTAghxSrK7AFYOCGZTblstnHerqs0Z/LTVNW2JaVkI34kvquqWdd6JJ+GNYWWuKuTiTjyEpLSikjXXFTWkLJqDU/w1Lq6MN6g+z6lx8=</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
</KeyValue>
</KeyInfo>
</Signature>
<FWT_CONFIG>
<keyName>#PEREXEMPAMT</keyName>
<keyValue>3100</keyValue>
</FWT_CONFIG>
<FWT_FORMULA>
<Step>1</Step>
<Token>MUL</Token>
<Arg1>@TAXWAGES</Arg1>
<Arg2>@PAYPERIODS</Arg2>
<Arg3>ANNUALWAGE</Arg3>
<Arg4 />
<Arg5 />
<Arg6 />
<Arg7 />
<Arg8 />
<DefValue>0</DefValue>
<Comment />
</FWT_FORMULA>
<FWT_TAXTABLES>
<filingStatus>1</filingStatus>
<taxTableId>3</taxTableId>
<baseWage>9700</baseWage>
<upperWage>30800</upperWage>
<taxAmt>705</taxAmt>
<taxRate>0.15</taxRate>
</FWT_TAXTABLES>
<FWT_TAXTABLES>
<filingStatus>1</filingStatus>
<taxTableId>4</taxTableId>
<baseWage>30800</baseWage>
<upperWage>68500</upperWage>
<taxAmt>3870</taxAmt>
<taxRate>0.25</taxRate>
</FWT_TAXTABLES>
</FWT>


:

Brian,

Can you post an example of the signed document?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

message
I have XML Documents that I am digitally signing, and need to be able
to
load
these documents into DataSet objects. However, after checking the
signature
and using the DataSet.ReadXML method, I am getting an exception "The
root
element is missing".

I have struggled over the last 24 hours trying to figure out ways of
correcting this, however I am stuck. I would appreciate any help
that
the
community can provide me on this.

Thanks,
 
Brian,

It's not an issue with the data set, but the position of the stream.
I'd focus there. If you save the XML to a file and load it into the data
set, it will work fine.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Brian W. Smith said:
Thanks again, I implemented your solution, however I am still receiving
the
same exception. Any ideas? I appreciate your looking into this for me.

Nicholas Paldino said:
Brian,

You are reading from the stream, but you are not resetting the
position,
it would seem. You basically want to do this before you read the data
set:

// Set the position to the beginning.
sr.BaseStream.Position = 0;

// Discard buffered data.
sr.DiscardBufferedData();

// Read normally.

That should work.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Brian W. Smith said:
Thanks for the quick reply. I am passing it in as a StreamReader, as I
am
using the same StreamReader to pull out the signature and verify it.
Below
is
the code that i am using.

sr is the StreamReader that contains the file


XmlDocument doc = new XmlDocument();

doc.Load(sr);
SignedXml verifier = new SignedXml(doc);
verifier.LoadXml(doc.GetElementsByTagName("Signature")[0] as
XmlElement);

if (verifier.CheckSignature())
{

this.GetConfigFileToScreen(sr);
}


public void GetConfigFileToScreen ( StreamReader sr )
{
DataSet ds1 = new DataSet();
ds1.ReadXml(sr); // This is the error line.


:

Brian,

I saved that XML document to a file, and then loaded it into a
DataSet
without any problems. Are you sure this is the right file, and how
are
you
loading it into the DataSet?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

message
Here is an example of the file. The file is used to create 3
datatables
in
the DataSet, I used the signature information in the first node
position
and
the last node. This example shows the signature in the first
position
using
the XmlDocument.DocumentElement.PrependChild() method.

Thanks

<?xml version="1.0" encoding="utf-8"?>
<FWT>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod
Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="">
<Transforms>
<Transform
Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
</Transforms>
<DigestMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"
/>
<DigestValue>hxyhMOAfdFJYOsDlADHTah0Gmmg=</DigestValue>
</Reference>
</SignedInfo>

<SignatureValue>rakRKha0vAX8cIsFwhJUsgzOB1NMNW6viG/EsTUivy4Rt3Cg2k1LDTkmJv+bXhgWBoPBtdMxg9ZSXah0P1qw5K/1npSWPmJ9uWGEQuWwZT5KqJNfq1iy7QKfUiKGTn1q+0Mc2WXPo18v6Fnuqqh7+btrpfnvbTaKJ0mQHAw9H+0=</SignatureValue>
<KeyInfo>
<KeyValue xmlns="http://www.w3.org/2000/09/xmldsig#">
<RSAKeyValue>

<Modulus>01k61JX5bc/jCLnnEHtzw3o08hs6+KjE58md8wkRrBgTTEU3gtmD1Q8SxPxpJiSwGNRCWTAghxSrK7AFYOCGZTblstnHerqs0Z/LTVNW2JaVkI34kvquqWdd6JJ+GNYWWuKuTiTjyEpLSikjXXFTWkLJqDU/w1Lq6MN6g+z6lx8=</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
</KeyValue>
</KeyInfo>
</Signature>
<FWT_CONFIG>
<keyName>#PEREXEMPAMT</keyName>
<keyValue>3100</keyValue>
</FWT_CONFIG>
<FWT_FORMULA>
<Step>1</Step>
<Token>MUL</Token>
<Arg1>@TAXWAGES</Arg1>
<Arg2>@PAYPERIODS</Arg2>
<Arg3>ANNUALWAGE</Arg3>
<Arg4 />
<Arg5 />
<Arg6 />
<Arg7 />
<Arg8 />
<DefValue>0</DefValue>
<Comment />
</FWT_FORMULA>
<FWT_TAXTABLES>
<filingStatus>1</filingStatus>
<taxTableId>3</taxTableId>
<baseWage>9700</baseWage>
<upperWage>30800</upperWage>
<taxAmt>705</taxAmt>
<taxRate>0.15</taxRate>
</FWT_TAXTABLES>
<FWT_TAXTABLES>
<filingStatus>1</filingStatus>
<taxTableId>4</taxTableId>
<baseWage>30800</baseWage>
<upperWage>68500</upperWage>
<taxAmt>3870</taxAmt>
<taxRate>0.25</taxRate>
</FWT_TAXTABLES>
</FWT>


:

Brian,

Can you post an example of the signed document?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

message
I have XML Documents that I am digitally signing, and need to be
able
to
load
these documents into DataSet objects. However, after checking the
signature
and using the DataSet.ReadXML method, I am getting an exception
"The
root
element is missing".

I have struggled over the last 24 hours trying to figure out ways
of
correcting this, however I am stuck. I would appreciate any help
that
the
community can provide me on this.

Thanks,
 
Thanks for the pointer... I had to reset the position before I build the
doc.LoadXML and then before I loaded the dataset... I really appreciate your
help... thanks.

Nicholas Paldino said:
Brian,

It's not an issue with the data set, but the position of the stream.
I'd focus there. If you save the XML to a file and load it into the data
set, it will work fine.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Brian W. Smith said:
Thanks again, I implemented your solution, however I am still receiving
the
same exception. Any ideas? I appreciate your looking into this for me.

Nicholas Paldino said:
Brian,

You are reading from the stream, but you are not resetting the
position,
it would seem. You basically want to do this before you read the data
set:

// Set the position to the beginning.
sr.BaseStream.Position = 0;

// Discard buffered data.
sr.DiscardBufferedData();

// Read normally.

That should work.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Thanks for the quick reply. I am passing it in as a StreamReader, as I
am
using the same StreamReader to pull out the signature and verify it.
Below
is
the code that i am using.

sr is the StreamReader that contains the file


XmlDocument doc = new XmlDocument();

doc.Load(sr);
SignedXml verifier = new SignedXml(doc);
verifier.LoadXml(doc.GetElementsByTagName("Signature")[0] as
XmlElement);

if (verifier.CheckSignature())
{

this.GetConfigFileToScreen(sr);
}


public void GetConfigFileToScreen ( StreamReader sr )
{
DataSet ds1 = new DataSet();
ds1.ReadXml(sr); // This is the error line.


:

Brian,

I saved that XML document to a file, and then loaded it into a
DataSet
without any problems. Are you sure this is the right file, and how
are
you
loading it into the DataSet?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

message
Here is an example of the file. The file is used to create 3
datatables
in
the DataSet, I used the signature information in the first node
position
and
the last node. This example shows the signature in the first
position
using
the XmlDocument.DocumentElement.PrependChild() method.

Thanks

<?xml version="1.0" encoding="utf-8"?>
<FWT>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod
Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="">
<Transforms>
<Transform
Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
</Transforms>
<DigestMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"
/>
<DigestValue>hxyhMOAfdFJYOsDlADHTah0Gmmg=</DigestValue>
</Reference>
</SignedInfo>

<SignatureValue>rakRKha0vAX8cIsFwhJUsgzOB1NMNW6viG/EsTUivy4Rt3Cg2k1LDTkmJv+bXhgWBoPBtdMxg9ZSXah0P1qw5K/1npSWPmJ9uWGEQuWwZT5KqJNfq1iy7QKfUiKGTn1q+0Mc2WXPo18v6Fnuqqh7+btrpfnvbTaKJ0mQHAw9H+0=</SignatureValue>
<KeyInfo>
<KeyValue xmlns="http://www.w3.org/2000/09/xmldsig#">
<RSAKeyValue>

<Modulus>01k61JX5bc/jCLnnEHtzw3o08hs6+KjE58md8wkRrBgTTEU3gtmD1Q8SxPxpJiSwGNRCWTAghxSrK7AFYOCGZTblstnHerqs0Z/LTVNW2JaVkI34kvquqWdd6JJ+GNYWWuKuTiTjyEpLSikjXXFTWkLJqDU/w1Lq6MN6g+z6lx8=</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
</KeyValue>
</KeyInfo>
</Signature>
<FWT_CONFIG>
<keyName>#PEREXEMPAMT</keyName>
<keyValue>3100</keyValue>
</FWT_CONFIG>
<FWT_FORMULA>
<Step>1</Step>
<Token>MUL</Token>
<Arg1>@TAXWAGES</Arg1>
<Arg2>@PAYPERIODS</Arg2>
<Arg3>ANNUALWAGE</Arg3>
<Arg4 />
<Arg5 />
<Arg6 />
<Arg7 />
<Arg8 />
<DefValue>0</DefValue>
<Comment />
</FWT_FORMULA>
<FWT_TAXTABLES>
<filingStatus>1</filingStatus>
<taxTableId>3</taxTableId>
<baseWage>9700</baseWage>
<upperWage>30800</upperWage>
<taxAmt>705</taxAmt>
<taxRate>0.15</taxRate>
</FWT_TAXTABLES>
<FWT_TAXTABLES>
<filingStatus>1</filingStatus>
<taxTableId>4</taxTableId>
<baseWage>30800</baseWage>
<upperWage>68500</upperWage>
<taxAmt>3870</taxAmt>
<taxRate>0.25</taxRate>
</FWT_TAXTABLES>
</FWT>


:

Brian,

Can you post an example of the signed document?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

message
I have XML Documents that I am digitally signing, and need to be
able
to
load
these documents into DataSet objects. However, after checking the
signature
and using the DataSet.ReadXML method, I am getting an exception
"The
root
element is missing".

I have struggled over the last 24 hours trying to figure out ways
of
correcting this, however I am stuck. I would appreciate any help
that
the
community can provide me on this.

Thanks,
 
Hi, Brian

I think you might change the contents in the Xml file by using "doc" , when
you call SignedXml constructor in the following context.

SignedXml verifier = new SignedXml(doc);

jason
Brian W. Smith said:
Thanks for the quick reply. I am passing it in as a StreamReader, as I am
using the same StreamReader to pull out the signature and verify it. Below is
the code that i am using.

sr is the StreamReader that contains the file


XmlDocument doc = new XmlDocument();

doc.Load(sr);
SignedXml verifier = new SignedXml(doc);
verifier.LoadXml(doc.GetElementsByTagName("Signature")[0] as XmlElement);

if (verifier.CheckSignature())
{

this.GetConfigFileToScreen(sr);
}


public void GetConfigFileToScreen ( StreamReader sr )
{
DataSet ds1 = new DataSet();
ds1.ReadXml(sr); // This is the error line.


Nicholas Paldino said:
Brian,

I saved that XML document to a file, and then loaded it into a DataSet
without any problems. Are you sure this is the right file, and how are you
loading it into the DataSet?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Here is an example of the file. The file is used to create 3 datatables in
the DataSet, I used the signature information in the first node position
and
the last node. This example shows the signature in the first position
using
the XmlDocument.DocumentElement.PrependChild() method.

Thanks

<?xml version="1.0" encoding="utf-8"?>
<FWT>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod
Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="">
<Transforms>
<Transform
Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<DigestValue>hxyhMOAfdFJYOsDlADHTah0Gmmg=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>rakRKha0vAX8cIsFwhJUsgzOB1NMNW6viG/EsTUivy4Rt3Cg2k1LDTkmJv+b
XhgWBoPBtdMxg9ZSXah0P1qw5K/1npSWPmJ9uWGEQuWwZT5KqJNfq1iy7QKfUiKGTn1q+0Mc2WXP
<Modulus>01k61JX5bc/jCLnnEHtzw3o08hs6+KjE58md8wkRrBgTTEU3gtmD1Q8SxPxpJiSwGNR
CWTAghxSrK7AFYOCGZTblstnHerqs0Z/LTVNW2JaVkI34kvquqWdd6JJ+GNYWWuKuTiTjyEpLSik
jXXFTWkLJqDU/w1Lq6MN6g+z6lx8= said:
<Exponent>AQAB</Exponent>
</RSAKeyValue>
</KeyValue>
</KeyInfo>
</Signature>
<FWT_CONFIG>
<keyName>#PEREXEMPAMT</keyName>
<keyValue>3100</keyValue>
</FWT_CONFIG>
<FWT_FORMULA>
<Step>1</Step>
<Token>MUL</Token>
<Arg1>@TAXWAGES</Arg1>
<Arg2>@PAYPERIODS</Arg2>
<Arg3>ANNUALWAGE</Arg3>
<Arg4 />
<Arg5 />
<Arg6 />
<Arg7 />
<Arg8 />
<DefValue>0</DefValue>
<Comment />
</FWT_FORMULA>
<FWT_TAXTABLES>
<filingStatus>1</filingStatus>
<taxTableId>3</taxTableId>
<baseWage>9700</baseWage>
<upperWage>30800</upperWage>
<taxAmt>705</taxAmt>
<taxRate>0.15</taxRate>
</FWT_TAXTABLES>
<FWT_TAXTABLES>
<filingStatus>1</filingStatus>
<taxTableId>4</taxTableId>
<baseWage>30800</baseWage>
<upperWage>68500</upperWage>
<taxAmt>3870</taxAmt>
<taxRate>0.25</taxRate>
</FWT_TAXTABLES>
</FWT>


:

Brian,

Can you post an example of the signed document?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have XML Documents that I am digitally signing, and need to be able to
load
these documents into DataSet objects. However, after checking the
signature
and using the DataSet.ReadXML method, I am getting an exception "The
root
element is missing".

I have struggled over the last 24 hours trying to figure out ways of
correcting this, however I am stuck. I would appreciate any help that
the
community can provide me on this.

Thanks,
 
Jason, I found that I had to reset the stream reader to position 0 in a
couple of places, as it was being passed from a caller to the displayed
method to one other method. So by the time that it got to the doc.LoadXml(sr)
statement the stream was at the end. I think when the stream is passed in to
the method the stream reader is advanced forward to the last position.
Because further testing showed that each time that I sent the stream reader
in as a parameter to a method the streamreader position would be EOF.

jji said:
Hi, Brian

I think you might change the contents in the Xml file by using "doc" , when
you call SignedXml constructor in the following context.

SignedXml verifier = new SignedXml(doc);

jason
Brian W. Smith said:
Thanks for the quick reply. I am passing it in as a StreamReader, as I am
using the same StreamReader to pull out the signature and verify it. Below is
the code that i am using.

sr is the StreamReader that contains the file


XmlDocument doc = new XmlDocument();

doc.Load(sr);
SignedXml verifier = new SignedXml(doc);
verifier.LoadXml(doc.GetElementsByTagName("Signature")[0] as XmlElement);

if (verifier.CheckSignature())
{

this.GetConfigFileToScreen(sr);
}


public void GetConfigFileToScreen ( StreamReader sr )
{
DataSet ds1 = new DataSet();
ds1.ReadXml(sr); // This is the error line.


Nicholas Paldino said:
Brian,

I saved that XML document to a file, and then loaded it into a DataSet
without any problems. Are you sure this is the right file, and how are you
loading it into the DataSet?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Here is an example of the file. The file is used to create 3 datatables in
the DataSet, I used the signature information in the first node position
and
the last node. This example shows the signature in the first position
using
the XmlDocument.DocumentElement.PrependChild() method.

Thanks

<?xml version="1.0" encoding="utf-8"?>
<FWT>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod
Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="">
<Transforms>
<Transform
Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<DigestValue>hxyhMOAfdFJYOsDlADHTah0Gmmg=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>rakRKha0vAX8cIsFwhJUsgzOB1NMNW6viG/EsTUivy4Rt3Cg2k1LDTkmJv+b
XhgWBoPBtdMxg9ZSXah0P1qw5K/1npSWPmJ9uWGEQuWwZT5KqJNfq1iy7QKfUiKGTn1q+0Mc2WXP
o18v6Fnuqqh7+btrpfnvbTaKJ0mQHAw9H+0= said:
<KeyInfo>
<KeyValue xmlns="http://www.w3.org/2000/09/xmldsig#">
<RSAKeyValue>
<Modulus>01k61JX5bc/jCLnnEHtzw3o08hs6+KjE58md8wkRrBgTTEU3gtmD1Q8SxPxpJiSwGNR
CWTAghxSrK7AFYOCGZTblstnHerqs0Z/LTVNW2JaVkI34kvquqWdd6JJ+GNYWWuKuTiTjyEpLSik
jXXFTWkLJqDU/w1Lq6MN6g+z6lx8= said:
<Exponent>AQAB</Exponent>
</RSAKeyValue>
</KeyValue>
</KeyInfo>
</Signature>
<FWT_CONFIG>
<keyName>#PEREXEMPAMT</keyName>
<keyValue>3100</keyValue>
</FWT_CONFIG>
<FWT_FORMULA>
<Step>1</Step>
<Token>MUL</Token>
<Arg1>@TAXWAGES</Arg1>
<Arg2>@PAYPERIODS</Arg2>
<Arg3>ANNUALWAGE</Arg3>
<Arg4 />
<Arg5 />
<Arg6 />
<Arg7 />
<Arg8 />
<DefValue>0</DefValue>
<Comment />
</FWT_FORMULA>
<FWT_TAXTABLES>
<filingStatus>1</filingStatus>
<taxTableId>3</taxTableId>
<baseWage>9700</baseWage>
<upperWage>30800</upperWage>
<taxAmt>705</taxAmt>
<taxRate>0.15</taxRate>
</FWT_TAXTABLES>
<FWT_TAXTABLES>
<filingStatus>1</filingStatus>
<taxTableId>4</taxTableId>
<baseWage>30800</baseWage>
<upperWage>68500</upperWage>
<taxAmt>3870</taxAmt>
<taxRate>0.25</taxRate>
</FWT_TAXTABLES>
</FWT>


:

Brian,

Can you post an example of the signed document?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have XML Documents that I am digitally signing, and need to be able to
load
these documents into DataSet objects. However, after checking the
signature
and using the DataSet.ReadXML method, I am getting an exception "The
root
element is missing".

I have struggled over the last 24 hours trying to figure out ways of
correcting this, however I am stuck. I would appreciate any help that
the
community can provide me on this.

Thanks,
 
If it is possible, can you write the original DataSet data into the xml
file by using the FillSchema and Fill methods of the DataAdapter?

with regards,


J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com
 
Back
Top