How to Trim xml tag " <?xml version="1.0" encoding="UTF-8"?> " RRS feed

  • Question

  • User-582711651 posted

    Hi friends, 

    ref this;

    </?xml version="1.0" encoding="UTF-8"?> <PrintLetterBarcodeData uid="1234567890" name="Mr.Joseph"... pc="601502" dob="12-06-1981"/>

    1. When I read QR code from QR Code Scanner most of the times I am getting values start with like this

    <?xml version="1.0" encoding="UTF-8"?>

    2. Some worst case getting values like these;

    </?xml version="1.0" encoding="UTF-8"?>


    QR-Code:<?xml version="1.0" encoding="UTF-8"?> (with prefix text QR-Code:)

    I don't want above 1 & 2 then I would like to trim upto  .....UTF-8"?>  then retain like below mentioned script only in textbox 

    <PrintLetterBarcodeData uid="1234567890" name="Mr.Joseph" ...... ... ... pc="601502" dob="12-06-1981"/>

    How I do, help me please. (expected in vb aspx) 

    Thanks in advance. 

    Wednesday, January 4, 2017 5:29 PM

All replies

  • User-1838255255 posted

    Hi ayyappan.CNN,

    According to your description, as far as I know, when you scan this file:

    1.  you could save it, then operate this XML file, foreach all elements.

    2. check all elements type, when detected node type equal to XmlDeclaration, move this node and re-save it. 

    Dim doc As New XmlDocument()
    For Each node As XmlNode In doc
    	If node.NodeType = XmlNodeType.XmlDeclaration Then
    	End If

    3. read this xml file, you will get the elements values.

    Best Regards,

    Eric Du

    Thursday, January 5, 2017 6:07 AM
  • User-582711651 posted

    Hi Eric, 

    I know these steps and how to segregate inner data its working well, before that I would like to trim,  this tag 

     <?xml version="1.0" encoding="UTF-8"?>

    some time it comes with " / " , like this  </?xml version="1.0" ...... that time I getting error in doc.load("something") 

    Hope you understand my requirement.  


    Thursday, January 5, 2017 6:59 AM
  • User753101303 posted


    The file is not valid. My first move would be to report that to those that are producing this file so that it is fixed once at the source rather than everywhere this file is consumed. This is a bug in the QR code reader?

    A temp fix could be to check specifically for this error (if the file content starts with "</?xml " replace that with "<?xml " and rewrite the file before processing it maybe. Then if or hopefully once the bug is fixed you could remove this workaround.

    Ah and same for QR-Code: (or they do have some doc that would explain about that ??? to me <?/xml is definitively invalid, not sure about the purpose of this "QR-Code:" prefix but crreating an invalid XML file seems really a bad idea and reporting about that will likely better help everyone rather than just fixing that on your side.

    Thursday, January 5, 2017 8:26 AM
  • User-582711651 posted

    Hi PatriceSc, 

    Thanks for your information, but for my exercise I don't want to keep and I would like to trim this tag only " <?xml version="1.0" encoding="UTF-8"?> " by using Ltrim(string), mid(string) request you to suggest one better solution (in vb.net).

    then I would like to retain balance xml data <PrintLetterBarcodeData uid="1234567890" name="Mr.Joseph" gender="MALE" yob="1981" co="S/O Steepan" lm="SN.Nagar" loc="null" vtc="Anna Nagar" po="Anna Nagar West" dist="Chennai" state="Tamil Nadu" pc="601502" dob="12-06-1981"/>

    see my vb.code 

    // Here I would like to trim that script and move into textbox ie. txt_xml_script.text //

    doc.LoadXml(Txt_XML_Script.Text) Dim root As XmlElement = doc.DocumentElement If root.HasAttribute("uid") Then f_uid = root.GetAttribute("uid") lbl_UID.Text = f_uid End If If root.HasAttribute("name") Then f_member = root.GetAttribute("name") End If If root.HasAttribute("gname") Then Dim gname As [String] = root.GetAttribute("gname") f_gname = gname End If

    ....... .... .. ... .
    .... ... .. ... .. .. ..

    Thanks in advance 

    Friday, January 6, 2017 9:36 AM
  • Thursday, January 19, 2017 12:00 PM