BaabuBangaram Posted March 2, 2017 Report Share Posted March 2, 2017 I have to implement a packet which will be in xml format <Printer> <printdata attr=here I have hexadecimaldata> </printdata> </Printer> This xml packet will be input to my one function. I need to read the hexadecimal data and process it further. my question is how to pass hexadecimal data and then while parsing how to parse it. I environment programming in C and embedded linux platform Quote Link to comment Share on other sites More sharing options...
BaabuBangaram Posted March 2, 2017 Author Report Share Posted March 2, 2017 LTT Quote Link to comment Share on other sites More sharing options...
fake_Bezawada Posted March 2, 2017 Report Share Posted March 2, 2017 <printdata yourattr="0023233232372372"> ila pedathav value attribute lo aythe ledu ah tag lo value pettali ante <printdata >008327932792323 </printdata> ila vuntundhi iha pothe parsing antava C lo ela cheyalo teliyadu but java lo aythe manchi APIS vunayi Quote Link to comment Share on other sites More sharing options...
fake_Bezawada Posted March 2, 2017 Report Share Posted March 2, 2017 idedo kanipinchindhi idenemo chudu #include <libxml/parser.h> Quote Link to comment Share on other sites More sharing options...
BaabuBangaram Posted March 2, 2017 Author Report Share Posted March 2, 2017 1 hour ago, fake_Bezawada said: <printdata yourattr="0023233232372372"> ila pedathav value attribute lo aythe ledu ah tag lo value pettali ante <printdata >008327932792323 </printdata> ila vuntundhi iha pothe parsing antava C lo ela cheyalo teliyadu but java lo aythe manchi APIS vunayi array of hex bytes kaavali like 0x123, 0x456,0x678 Quote Link to comment Share on other sites More sharing options...
MegaPowerRockstar Posted March 2, 2017 Report Share Posted March 2, 2017 C# aythe you can use xml qury and xpath to extract the data in attribute XML Data: <Employees> <EmployeeName id ="Ven234">Venkata Sreenivas</EmployeeName> <EmployeeAge>30</EmployeeAge> <Employees> Code: XPathNavigator xpathCancelType = xPathNav.SelectSingleNode("//Employees/EmployeeName"); if (xpathCancelType != null) { var personID = xpathCancelType.GetAttribute("id", ""); } Quote Link to comment Share on other sites More sharing options...
karthikn Posted March 2, 2017 Report Share Posted March 2, 2017 5 hours ago, BaabuBangaram said: I have to implement a packet which will be in xml format <Printer> <printdata attr=here I have hexadecimaldata> </printdata> </Printer> This xml packet will be input to my one function. I need to read the hexadecimal data and process it further. my question is how to pass hexadecimal data and then while parsing how to parse it. I environment programming in C and embedded linux platform <![CDATA[]]> look into this tag n how to read it Quote Link to comment Share on other sites More sharing options...
Luke Posted March 2, 2017 Report Share Posted March 2, 2017 29 minutes ago, karthikn said: <![CDATA[]]> look into this tag n how to read it Quote Link to comment Share on other sites More sharing options...
MegaPowerRockstar Posted March 2, 2017 Report Share Posted March 2, 2017 3 hours ago, karthikn said: <![CDATA[]]> look into this tag n how to read it use the below code to read data from string variable string sourceData = ""; // xml content is here byte[] sourceBytes = Encoding.UTF8.GetBytes(sourceData); MemoryStream sourceStream = new MemoryStream(sourceBytes); XPathDocument sourceXPathDoc = new XPathDocument(new StringReader(sourceData)); sourceMappingXNav = sourceXPathDoc.CreateNavigator(); Quote Link to comment Share on other sites More sharing options...
karthikn Posted March 2, 2017 Report Share Posted March 2, 2017 17 minutes ago, MegaPowerRockstar said: use the below code to read data from string variable string sourceData = ""; // xml content is here byte[] sourceBytes = Encoding.UTF8.GetBytes(sourceData); MemoryStream sourceStream = new MemoryStream(sourceBytes); XPathDocument sourceXPathDoc = new XPathDocument(new StringReader(sourceData)); sourceMappingXNav = sourceXPathDoc.CreateNavigator(); pilladu c and embedded anta.. can't use this also XDocument XElement chala better compared to XPath.. direct ga descendantnodes attributes find cheyadam Quote Link to comment Share on other sites More sharing options...
dasara_bullodu Posted March 2, 2017 Report Share Posted March 2, 2017 9 hours ago, BaabuBangaram said: I have to implement a packet which will be in xml format <Printer> <printdata attr=here I have hexadecimaldata> </printdata> </Printer> This xml packet will be input to my one function. I need to read the hexadecimal data and process it further. my question is how to pass hexadecimal data and then while parsing how to parse it. I environment programming in C and embedded linux platform Hex to decimal conversion aithe 0x123 = (3 * 16^0) + (2 * 16^1) + (1 * 16^2) basically sum of (n * 16^(reverse index of n)) for each number if n = a, make it 10, b -> 11, c -> 12, d -> 13, e -> 14, f -> 15 decimal to hex conversion aithe 123 n = 123 first number = n %16 - (if firstnumber = 10, make it a, 11 -> b, 12 -> c, 13-> d, 14-> e, 15 -> f) then n = n/16 secondnumber = n % 16 ... do this till n > 0 Quote Link to comment Share on other sites More sharing options...
BaabuBangaram Posted March 3, 2017 Author Report Share Posted March 3, 2017 7 hours ago, dasara_bullodu said: Hex to decimal conversion aithe 0x123 = (3 * 16^0) + (2 * 16^1) + (1 * 16^2) basically sum of (n * 16^(reverse index of n)) for each number if n = a, make it 10, b -> 11, c -> 12, d -> 13, e -> 14, f -> 15 decimal to hex conversion aithe 123 n = 123 first number = n %16 - (if firstnumber = 10, make it a, 11 -> b, 12 -> c, 13-> d, 14-> e, 15 -> f) then n = n/16 secondnumber = n % 16 ... do this till n > 0 Direct hex bytes pampinchalem antaav anthena.......hex ni integer loki convert cheyyali antaav Quote Link to comment Share on other sites More sharing options...
fake_Bezawada Posted March 3, 2017 Report Share Posted March 3, 2017 array vunaya neeku hex then make multiple tags <Printer> <printdata>hex data 1</printdata> <printdata>hex data 2</printdata> <printdata>hex data 3</printdata> <printdata>hex data 4</printdata> <printdata>hex data 5</printdata> </Printer> parse chesi napudu motham values common tag name tho call chesthe array loki vatchesthay Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.