Options

Line Break in XML Files?

ta5ta5 Member Posts: 1,164
Hi

I've created an XML Document in Navision using the DOM Object and some functions of code unit 6224. That's quite ok, the file looks ok in a viewer programm (internet explorer for example).
If viewed with a text editor, there are no line breaks in the file. This is a problem if the file later causes a parsing error (XMLParseError.line is useless and XMLParseError.src l would exceed 1024 characters).

As I understand, line breaks are not part of the xml specification, but become very handy for debugging reasons.

Any ideas?
Many thanks in advance
Thomas

Comments

  • Options
    pduckpduck Member Posts: 147
    no ... but we find that some other parsers have problems when the xml contains a linebreak.

    we use this function to get most of the information:
    INF_DOM_PARSEERROR:
    DOM-Error: "%1" in "%2"\\Reason: "%3"\\Line: %4\Column: %5\File position: %6\\Comment: %7
    
    ShowDOMParseError(vau_ParseError : Automation "'Microsoft XML, v4.0'.IXMLDOMParseError";vtx_AddMsgText : Text[250];vbn_ShowAsError : Boolean)
    
    IF vbn_ShowAsError THEN
      ERROR(INF_DOM_PARSEERROR,
            FORMAT(vau_ParseError.errorCode),
            vau_ParseError.url,
            vau_ParseError.reason,
            FORMAT(vau_ParseError.line),
            FORMAT(vau_ParseError.linepos),
            FORMAT(vau_ParseError.filepos),
            vtx_AddMsgText)
    ELSE
      MESSAGE(INF_DOM_PARSEERROR,
              FORMAT(vau_ParseError.errorCode),
              vau_ParseError.url,
              vau_ParseError.reason,
              FORMAT(vau_ParseError.line),
              FORMAT(vau_ParseError.linepos),
              FORMAT(vau_ParseError.filepos),
              vtx_AddMsgText);
    

    and don't try to put srcText in the message when working with very big files :)
  • Options
    ta5ta5 Member Posts: 1,164
    Thank you for your message. Works very well.

    There is another problem with validation:
    To validate a xmlDoc against its schema, I often use a function similar to function validatexmldocument in codeunit 99008518. This works sometimes ok, but sometimes only with xml4-objects and sometimes not at all (when it does not work an error occurs in the add-method of the schemacache -- so I have no chance to handle the error).

    As far as I know, there are 3 concepts to test against a schema: noNameSpaceSchemaLocation, schemaLocation and schema cache. I guess schema cache is convenient, because it does not depend on a given filename in the xmlDoc.

    Do you have a "bullet proof" method to validate against its schema?

    Many thanks in advance
    Thomas
  • Options
    pduckpduck Member Posts: 147
    sorry we haven't. because of all the different specifications for schemas and their validation (every parser version uses another way) we only validate against dtd if we need a validation now.
Sign In or Register to comment.