EldoS | Feel safer!

Software components for data protection, secure storage and transfer

TElXMLDOMDocument, create an instance based on a string

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#4067
Posted: 10/19/2007 05:47:34
by Nuno Guedes (Basic support level)
Joined: 08/13/2007
Posts: 87

hi, i am trying to pass my verification process to a web service.

In the web page for verification i access file and read his content for a TElXMLDOMDocument.
Then i invoke the web service passing the string TElXMLDOMDocument.OuterXML. After this i need to convert the string to a TElXMLDOMDocument. I tryed it from different ways and i didn´t found a solution. The best aproach was create a memorystream with the string received and then invoke the TElXMLDOMDocument.LoadFromStream method but this return an exception "Object reference not set to an instance of an object".

How can i do this?

thanks
#4070
Posted: 10/19/2007 07:12:28
by Eugene Mayevski (EldoS Corp.)

Can you please specify the piece of code that causes the error?


Sincerely yours
Eugene Mayevski
#4074
Posted: 10/19/2007 08:12:55
by Nuno Guedes (Basic support level)
Joined: 08/13/2007
Posts: 87

This is the method in the web page that invokes the web service
Code
      public string validarAssinatura(int indice)
        {
            FileStream F = null;
            TElXMLDOMDocument FXMLDocument = new TElXMLDOMDocument();
            localhost.ServicosSobreAssinaturas servico = new WebSite.localhost.ServicosSobreAssinaturas();
            localhost.ResponseObject resultado = new WebSite.localhost.ResponseObject();

            try
            {
                F = new FileStream("C:/ebanka/eBankaNG-dev/eBanka FrontEnd/WebSite/Signature/teste.xmlSign.xml", FileMode.Open, FileAccess.Read);
                FXMLDocument.LoadFromStream(F, "", true);
            }

            catch (Exception E)
            {
                lbErro.Text = "Error: " + E.Message;
                return estado.INVALIDA.ToString();
            }

            resultado = servico.VerificarAssinatura(FXMLDocument.OuterXML, indice);

            if (F != null)
                F.Close();

            lbErro.Text = resultado.erro;
            lbAData.Text = resultado.signatureTime;
            lbCTData.Text = resultado.timestampTime;
            lbResultado.Text = resultado.estado;
                    
            return resultado.estado;
        }


This is the code of the web service, the error is catched by the final "catch".
Code
        [WebMethod]
        public ResponseObject VerificarAssinatura(string xml, int indice)
        {
            TElXMLDOMDocument FXMLDocument = null;
            TElXMLDOMNode Node;
            TElXMLVerifier Verifier;
            TElXAdESVerifier XAdESVerifier;

            ResponseObject result = new ResponseObject();

            //FXMLDocument = xml;

            //System.Xml.XmlDocument f = new System.Xml.XmlDocument();
            //f.LoadXml(xml);
            //FXMLDocument = ((TElXMLDOMDocument) f);

            MemoryStream teste = new MemoryStream();
            StreamWriter w = new StreamWriter(teste);
            w.Write(xml);

            try
            {
                FXMLDocument.LoadFromStream(teste);
            }
            catch (Exception E)
            {
                result.erro = string.Format("Signature data loading failed. ({0})", E.Message);
                return result;
            }
}
#4084
Posted: 10/19/2007 13:14:20
by Dmytro Bogatskyy (EldoS Corp.)

The OuterXML is readonly property, to set data you should use ElXMLElement.InnerXML property. But ElXMLDocument doesn't have InnerXML property, so you can do following:
Code
Document = new TElXMLDocument();
TElXMLDOMElement Element = SBXMLCore.Unit.ParseElementFromXMLString(XmlData, Document);
Document.AppendChild(Element);


Quote
The best aproach was create a memorystream with the string received and then invoke the TElXMLDOMDocument.LoadFromStream method but this return an exception "Object reference not set to an instance of an object".

You saved to stream a unicode data, and it doesn't contain a UTF-16 BOM (Byte Order Mark), because you saved using OuterXML property. So, LoadFromStream couldn't detect the encoding. Try: LoadFromStream(teste, "utf-16")
And, before LoadFromStream call set:
teste.Position = 0;
#4088
Posted: 10/19/2007 14:14:19
by Nuno Guedes (Basic support level)
Joined: 08/13/2007
Posts: 87

thanks, i will try your first advice
#4106
Posted: 10/22/2007 06:17:16
by Nuno Guedes (Basic support level)
Joined: 08/13/2007
Posts: 87

hi,

i tryed your first advice

Code
Document = new TElXMLDocument();
TElXMLDOMElement Element = SBXMLCore.Unit.ParseEleme­ntFromXMLString(XmlData, Document);
Document.AppendChild(Elem­ent);


and it works fine.

thanks
#17684
Posted: 09/29/2011 08:31:19
by Petar  (Basic support level)
Joined: 08/31/2011
Posts: 6

Hello,

what is the best practice for creating TElXMLDOMElement, or TElXMLDOMDocument from a string?

Example listed below throws this error: XML parse error at position 39 (0x27): you can't use "<?xml" here.

Code
TElXMLDOMDocument Document = new TElXMLDOMDocument();
TElXMLDOMElement Element = SBXMLUtils.Unit.ParseElementFromXMLString(xml, Document);
Document.AppendChild(Element);


String (UTF-8) starts like this:
Code
<?xml version=\"1.0\" encoding=\"UTF-8\"?><Zig xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n  <XmlVersion>1.0</XmlVersion> ...
#17686
Posted: 09/29/2011 08:46:58
by Vsevolod Ievgiienko (EldoS Corp.)

Hello.

Try to write your string to an instance of System.IO.MemoryStream and load it using TElXMLDOMDocument.LoadFromStream() method. Do not forget to set stream position to zero before calling this method.
#17688
Posted: 09/29/2011 08:56:02
by Petar  (Basic support level)
Joined: 08/31/2011
Posts: 6

Hello,

thank you for your reply. It works.
Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.

Reply

Statistics

Topic viewed 3903 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!