Options

create and read a xml file

ondinaondina Member Posts: 9
I have a problem whem I read a xml file.

I create a xml file like this:


IF ISCLEAR(XMLDocOut) THEN
CREATE(XMLDocOut);

ReturnValue := FALSE;

XMLDocOut.loadXML ('<?xml version="1.0" encoding="ISO-8859-1" ?><SERVICO/>');


XMLCurrNode := XMLDocOut.documentElement;

IF AddElement(XMLCurrNode,'CODSERV','XXXX',DocNameSpace,XMLNewChild) > 0 THEN
EXIT;
IF AddElement(XMLCurrNode,'DES','X(80)X',DocNameSpace,XMLNewChild) > 0 THEN
EXIT;
....



And everything seems ok.


Then I try to read the file, this way:


Ficheiro := 'C:\FICH_DGO\IN\FICH00.xml';
XMLFile.OPEN(Ficheiro);
XMLFile.CREATEINSTREAM(XMLInStr);

IF ISCLEAR(XMLDocIn) THEN
CREATE(XMLDocIn);

XMLDocIn.load(XMLInStr);

XMLFile.CLOSE();

XMLNode := XMLDocIn.documentElement;

XMLRootNode := XMLDocIn.documentElement;

//MESSAGE(XMLNode.nodeName);

IF FindNode(XMLNode,'SERVICO',XMLNodeFound) THEN BEGIN
XMLNode := XMLNodeFound;

IF FindNode(XMLNode,'CODSERV',XMLNodeFound) THEN
IF STRLEN(XMLNodeFound.text) > 0 THEN
MESSAGE(XMLNodeFound.text);

IF FindNode(XMLNode,'DES',XMLNodeFound) THEN
IF STRLEN(XMLNodeFound.text) > 0 THEN
MESSAGE(XMLNodeFound.text);
.....



The function FindNode() and AddElement() are the same that exist in Navision, I haven't modified them.

Why doesn't the red instruction work ?
Is that possible that the problem is when I create the file or when I read it ?

Thanks for your time.

Ondina

Comments

  • Options
    eromeineromein Member Posts: 589
    Did you take a look at this tool:

    http://www.mibuso.com/dlinfo.asp?FileID=285
    "Real programmers don't comment their code.
    If it was hard to write, it should be hard to understand."
  • Options
    fbfb Member Posts: 246
    The 'selectSingleNode' method of the XML DOM uses 'XPath' syntax for the search arguments. See the following reference:

    http://msdn.microsoft.com/library/defau ... Syntax.asp

    XPath syntax has some similarity to ms-dos directory names, and that similarity can help in forming search expressions...

    Your xml document has the following 'directory tree'...

    /SERVICO
    /SERVICO/CODSERV
    /SERVICO/DES

    When you code the line 'xmlNode := ...documentElement', you are positioned at '/SERVICO' in the tree. Doing a FindNode (which calls the selectSingleNode method) with a search expression that does not begin with a '/' will search 'below' the current position -- and won't find any 'SERVICO' node(s) 'below' the root node.

    I think that if you change the search expression to '/SERVICO', then you will find the root node (and XMLNodeFound will be the same as XMLNode...).
  • Options
    ondinaondina Member Posts: 9
    \:D/ It's the first time I do anything with xml. I just have a little ideia about what is a xml file.
    Thanks. You have save me.
Sign In or Register to comment.