How to find xml valaue in xml file

Hi,

I want to find a value between the node: 6777

So the value: 6777.

This is the complete xml file:

<?xml version="1.0" encoding="utf-8"?> goed bedrijf Solutions99 Akkabi n Hertenrade 113 2544 he Den haag Info@noa-it.com Eenmanszaak 2578723 Nl145155663B02 verplicht verplicht Nl41ingb0006618174 kontant nee ja Info@noa-it.com Nawil Akkabi Nak@noa-it.com 0624420920 Eigenaar Ja Ja Ja Ja Ja Ja Ja

Thank you

Hi,

You can use XML Ports on Navision or DotNet variables.

The link below describe an example of reading XmlDocument with DotNet variables.
msdn.microsoft.com/…/hh166527(v=nav.90).aspx

See Codeunit 6224.

Thank you for your answare.

I am using this:

// The import function in NAV cant handle with the xmlns line in the xml file. So a work around is to strip the line with the
//xmlns in it.
dFile.TEXTMODE(FALSE);
dFile.OPEN(Filename);
dFile.CREATEINSTREAM(Stream);
InputText.READ(Stream);
dFile.CLOSE;

duplicateChambreofCommerce.SETRANGE(“Chamber of Commerce no.”,duplicateChambreofCommerce.“Chamber of Commerce no.”);
IF duplicateChambreofCommerce.FINDFIRST THEN
ERROR(‘nummer bestaat al’);

TextToFind :=’ xmlns:xsd="www.w3.org/…/XMLSchema" xmlns:xsi="www.w3.org/…/XMLSchema-instance"’;
TextPos := InputText.TEXTPOS(TextToFind);
TextToFindKVKBegin :=’’;
TextToFindKVKEnd := ‘’;

WHILE TextPos <> 0 DO BEGIN
InputText.GETSUBTEXT(SubText, 1, TextPos - 1);
OutputText.ADDTEXT(SubText);

InputText.GETSUBTEXT(InputText, TextPos + STRLEN(TextToFind));
TextPos := InputText.TEXTPOS(TextToFind);

END;
OutputText.ADDTEXT(InputText);

dFile.TEXTMODE(FALSE);
dFile.CREATE(Filename);
dFile.CREATEOUTSTREAM(NVOutStream);
OutputText.WRITE(NVOutStream);
dFile.CLOSE;

IF ISSERVICETIER THEN BEGIN
IF UPLOADINTOSTREAM(
‘Select the simple.xml file’,
‘\svdh04\data\NAV docs\webaanmelding’,
‘XML File *.xml| *.xml’,
Filename,
Stream) THEN
MESSAGE(ImportCompleteText)
ELSE
EXIT;
END
ELSE BEGIN
dFile.OPEN(Filename);
dFile.CREATEINSTREAM(Stream);
IF NOT XMLPORT.IMPORT(50010,Stream) THEN MESSAGE(ErrorText)
ELSE MESSAGE(ImportCompleteText);
END;

IF NOT ISSERVICETIER THEN dFile.CLOSE;

But so how to find the value of:27342867?

Thank you

Hi Niels,
Than you will have to continue searching for a long time. That value is not in your file.
But exactly what is it that you’re trying to do? Is it related to your other question?

As a general rule, then I never import directly into NAV using XMLPorts. At least not when it’s tables that are just a little complex. I always uses my own little Import Development Pattern.

  1. Import file into an Import Queue table in a BLOB field.
  2. XMLPort reads data into “import buffer file” (temporary)
  3. Verify import buffer - validation - record errors in file - sets status in import queue to error or verified (or skipped)
  4. Reads the verified buffer file to the record.
    The advantage of this “pattern” is to ensure that we always can say why a file was not imported, and if required just verify and read it again. It’s something I build quite some years ago, and has continued to “enhance”. But a lot less than what I had could do it. Remember that the “temporary” buffer file is not required to be included in the customers license, as you never inserts the data into the table.

I actually wrote my last reply Xhavat, but forgot to press post!

To read a value from an XML file you first you need to pass it to the file to an outstream and then to the XMLDocument.

Here you then load the node list (which I think you don’t need, as you have no nodes your that file). After you have fetched the node list (if it exists), then you can read the actual XML node.


IF ISCLEAR(XMLDoc) THEN
  CREATE(XMLDoc);

XMLDoc.load(oStream);

IF NodeListExists(XMLDoc,Node,'/') THEN
  LoadNodeListAndNode(XMLDoc,NodeList,Node,'/')
ELSE
  ERROR('No child nodes');

IF GetNodeText(Node,'<Kvk>') = '6777' THEN;

        
    PROCEDURE LoadNodeListAndNode@1000000002(VAR XMLDocument@1100006000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A05-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.DOMDocument60";VAR XMLNodeList@1100006002 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF82-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNodeList";VAR XMLNode@1100006001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNode";ElementName@1000000000 : Text[250]);
    VAR
      NodeLength@1000000004 : Integer;
    BEGIN
      XMLNodeList := XMLDocument.selectNodes(ElementName);

      NodeLength := XMLNodeList.length;
      XMLNode := XMLNodeList.item(0);
    END;

    PROCEDURE NodeListExists@1000000009(VAR XMLDocument@1100006003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A05-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.DOMDocument60";VAR XMLNode@1100006000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNode";ElementName@1000000000 : Text[250]) : Boolean;
    BEGIN
      XMLNode := XMLDocument.selectSingleNode(ElementName);
      IF NOT ISCLEAR(XMLNode) THEN
        EXIT(XMLNode.hasChildNodes)
      ELSE
        EXIT(FALSE);
    END;

    LOCAL PROCEDURE GetNodeText@1000000031(VAR Element@1100006002 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A05-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.DOMDocument60";NodeName@1000000002 : Text[50]) : Text[1024];
    VAR
      Node@1100006001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNode";
      DebugTxt@1000000004 : Text[1023];
    BEGIN
      Node := Element.selectSingleNode(NodeName);
      IF ISCLEAR(Node) THEN
        EXIT('');

      EXIT(Node.text);
    END;

Thank you for your reply,

but I dont understand this:

GetNodeText@1000000031(VAR Element@1100006002 : Automation “{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A05-F192-11D4-A65F-0040963251E5}:‘Microsoft XML, v6.0’.DOMDocument60”;NodeName@1000000002 : Text[50]) : Text[1024];

But I have put all the code for reading a xml file. So how to put your example in the code I already have?

And is the datatype of: XMLDocument?

And I see in your code that you have hard coded the number: 6777. But that is ofcourse every time different.

Thank you