How to read an irregular xml string after change it to stream in C# -


how read irregular xml string after change stream in c#?

here code have far:

string modoentrada = "01"; string xml= "";  xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; xml += "<transaccion xmlns=\"http://www.prosa.com.mx/xsd/\">"; //xml = "<transaccion>"; xml += "<autorizacionrequest>"; xml += "<modoentrada>" + modoentrada + "</modoentrada>"; //target xml += "</autorizacionrequest>"; xml += "</transaccion>"; xml.replace(" ","_");  byte[] bytearray = encoding.utf8.getbytes(xml); stream stream = new memorystream(bytearray);  xmldocument xmldoc = new xmldocument(); xmldoc.load(stream); xmlnode x = xmldoc.selectsinglenode("/autorizacionrequest/modoentrada"); 

the problem is: x == null

it works <transaccion> instead of <transaccion xmlns="http://www.prosa.com.mx/xsd">.

add namespacemanager , use in xpath

  xmldocument xmldoc = new xmldocument();   xmldoc.load(stream);    var xmlnsm = new xmlnamespacemanager(xmldoc.nametable);   xmlnsm.addnamespace("tr", @"http://www.prosa.com.mx/xsd/");    xmlnode x = xmldoc.selectsinglenode("/tr:transaccion/tr:autorizacionrequest/tr:modoentrada", xmlnsm ); 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -