Problems when generating a file xml

haritza10haritza10 Member Posts: 28
edited 2007-02-07 in Navision Attain
I have a problem when generating a file xml.
The problem is the following one: I need to put schema in the document xml and this I do adding it to him an attribute and this it is a node father. After I create a son of this node father and then the node son inherits the label xmlns = "". I could need that this node son did not inherit east attribute to me. Not if the programming with that I generate the attribute is the correct one, with which could need that somebody supervised this. The code to generate the file xml is the following one:

IF "Hist. Alb".FIND('-') THEN
REPEAT;
Lineas.RESET;
Lineas.SETRANGE(Lineas."Document No.","Hist. Alb"."No.");

//** Make a xml doc and the main structure
CLEAR(XMLDocOut);
CREATE(XMLDocOut);
XMLDOMManagement.SetNormalCase;
XMLProccesingInst := XMLDocOut.createProcessingInstruction('xml','version=''1.0'' encoding=''windows-1252''');
XMLCurrNode := XMLDocOut.appendChild(XMLProccesingInst);
CLEAR(XMLCurrNode);

{***********Here is where i put the atribute and node son inherit**********************************************************}
//** Main node OpenShipments with his schema
XMLCurrNode := XMLDocOut.createElement('OpenShipments');
XMLCurrNode := XMLDocOut.appendChild(XMLCurrNode);
IF XMLDOMManagement.AddAttribute(XMLCurrNode,'xmlns',
'x-schema:c:\OpenShipments.xdr') > 0 THEN EXIT;

{************** I prove to generate with xmlschema but i haver errors
******************************}
{
XMLSchema := XMLCurrNode;
XMLSchema.add('xmlns="x-schema:c:\OpenShipments.xdr"','OpenShipments');
XMLCurrNode := XMLDocOut.appendChild(XMLCurrNode);
CLEAR(XMLCurrNode);
}
//** OpenShipment node
XMLDOMManagement.AddElement(XMLCurrNode,'OpenShipment','','',XMLCurrNode);
IF XMLDOMManagement.AddAttribute(XMLCurrNode,'ProcessStatus','') > 0 THEN EXIT;

//** Receiver's node
IF XMLDOMManagement.AddElement(XMLCurrNode,'Receiver','','',XMLCurrNode2) > 0 THEN EXIT;

//** receptor's information
IF XMLDOMManagement.AddElement(XMLCurrNode2,'CompanyName',
"Hist. Alb"."Ship-to Name" + "Hist. Alb"."Ship-to Name 2",'',XMLNewChild) > 0 THEN EXIT;
IF XMLDOMManagement.AddElement(XMLCurrNode2,'ContactPerson',
"Hist. Alb"."Ship-to Contact",'',XMLNewChild) > 0 THEN EXIT;
IF XMLDOMManagement.AddElement(XMLCurrNode2,'AddressLine1',
"Hist. Alb"."Ship-to Address",'',XMLNewChild) > 0 THEN EXIT;
IF XMLDOMManagement.AddElement(XMLCurrNode2,'AddressLine2',
"Hist. Alb"."Ship-to Address 2",'',XMLNewChild) > 0 THEN EXIT;
IF XMLDOMManagement.AddElement(XMLCurrNode2,'AddressLine3',
"Hist. Alb"."Ship-to County",'',XMLNewChild) > 0 THEN EXIT;
IF XMLDOMManagement.AddElement(XMLCurrNode2,'City',
"Hist. Alb"."Ship-to City",'',XMLNewChild) > 0 THEN EXIT;
IF XMLDOMManagement.AddElement(XMLCurrNode2,'CountryCode',
'ES','',XMLNewChild) > 0 THEN EXIT;
IF XMLDOMManagement.AddElement(XMLCurrNode2,'PostalCode',
"Hist. Alb"."Ship-to Post Code",'',XMLNewChild) > 0 THEN EXIT;

//** emitter's node
IF XMLDOMManagement.AddElement(XMLCurrNode,'Shipment','','',XMLCurrNode2) > 0 THEN EXIT;

IF XMLDOMManagement.AddElement(XMLCurrNode2,'ServiceLevel',
"Hist. Alb"."Shipment Method Code",'',XMLNewChild) > 0 THEN EXIT;
IF XMLDOMManagement.AddElement(XMLCurrNode2,'NumberOfPackages',
FORMAT("Hist. Alb"."Nºbultos"),'',XMLNewChild) > 0 THEN EXIT;
IF XMLDOMManagement.AddElement(XMLCurrNode2,'ShipmentActualWeight',
FORMAT("Hist. Alb"."Peso bruto"),'',XMLNewChild) > 0 THEN EXIT;
IF XMLDOMManagement.AddElement(XMLCurrNode2,'Reference1',
"Hist. Alb"."No.",'',XMLNewChild) > 0 THEN EXIT;
IF XMLDOMManagement.AddElement(XMLCurrNode2,'BillingOption',
'PP','',XMLNewChild) > 0 THEN EXIT;


XMLDocOut.save('c:\'+ "Hist. Alb"."No." + '.xml');

UNTIL "Hist. Alb".NEXT = 0;

Comments

  • eromeineromein Member Posts: 589
    dude,

    I've got no idea what you are talking about. But please take a look at this:
    IF ISCLEAR(XMLSchema) THEN
      CREAT(XMLSchema);
    
    XMLSchema.add('',XSDFileName);
    
    MSXMLDomDocument.asunc := false;
    MSXMLDomDocument.Schemas := XMLSchema;
    

    Maybe it's something usefull
    "Real programmers don't comment their code.
    If it was hard to write, it should be hard to understand."
  • haritza10haritza10 Member Posts: 28
    Thanks a lot eromein, i'm going to prove
  • Stefan_HillmannStefan_Hillmann Member Posts: 9
    First of all there are several ways of assigning schemas to the xml-stream.
    You have to look at the schema-type you are using to decide which way does correspond to your problem...

    when using DTD you may use the following example while the MSXML-Parser is not designed for adding DOCTYPE-declarations:
    RootNode := XMLDOM.createElement('TEST');
    XMLDOM.appendChild(RootNode);
    XMLDOM.loadXML('<?xml version="1.0" encoding="UTF-8"?>' +
    '<!DOCTYPE TEST SYSTEM "' +
    ...your schema file...
    
    + '">' XMLDOM.xml);


    when using XDR try this example:
    NamespaceURI := 'x-schema:' +
    ...your schema file...
    
    ;
    PI := XMLDOM.createProcessingInstruction('xml','version="1.0" encoding="UTF-8"');
    XMLDOM.appendChild(PI);
    RootNode := XMLDOM.createNode(1,'TEST',NamespaceURI);


    when using XSDs try this:
    NamespaceURI :=
    ...your namespace...
    
    ;
    PI := XMLDOM.createProcessingInstruction('xml','version="1.0" encoding="UTF-8"');
    XMLDOM.appendChild(PI);
    RootNode := XMLDOM.createNode(1,'TEST',NamespaceURI);
    RootNode.setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
    IF NamespaceURI = '' THEN BEGIN
    RootNode.setAttribute('xsi:noNamespaceSchemaLocation',
    ...your schemafile...
    
    );
    END ELSE
    RootNode.setAttribute('xsi:schemaLocation',NamespaceURI + ' ' +
    ...your schemafile...
    
    );


    I hope that this little code example helps you fixing your problem.
    You may use the kind of encoding you like.

    Please feel free to response in order to awake a kind of discussing group for themes "XML and Navision", "XML and NAS" and so on... ???


    Stefan
  • froewisfroewis Member Posts: 5
    Hallo!

    I have tried your code to give a dtd to my xml but i need not a file path. I need the full text of the dtd in my xml because the communikation server need this.

    So I have saved the text on my volume an make an instream. So this is a workaround.

    I would like to find another way to save the dtd in my xml file.

    May be you have an idea.

    Christian
  • jensthomsenjensthomsen Member Posts: 173
    Hi Froewis
    I seem to have the same problem...I need to "save" a file (.pdf, .tiff etc) in a XML document created by MSDom. Could you tell how to make the instream??
    And by the way: What is a "dtd"??
    Jens
Sign In or Register to comment.