XML with empty attributes

Hunki
Member Posts: 5
I wrote some code to create an xml-file with XML-Dom in Navision 2009 SP1.
Till here, this is nothing special. The problem is, that every time I add an attribute to a node it will create a empty attribute on the next element.
<?xml version="1.0" encoding="ISO-8859-1"?>
<DeclareSalary xmlns="http://www.swissdec.ch/schema/sd/20090803/SalaryDeclarationServiceTypes">
<RequestContext xmlns="http://www.swissdec.ch/schema/sd/20090803/SalaryDeclarationContainer">
<UserAgent xmlns=""/>
<CompanyName xmlns=""/>
</RequestContext>
</DeclareSalary>
What can I do that these empty attributes will not occur? Does anybody has a idea?
No, i cannot create it with XML-Ports.... the code is to complex to simly use an xml port.
Thanks
Patrick
Till here, this is nothing special. The problem is, that every time I add an attribute to a node it will create a empty attribute on the next element.
<?xml version="1.0" encoding="ISO-8859-1"?>
<DeclareSalary xmlns="http://www.swissdec.ch/schema/sd/20090803/SalaryDeclarationServiceTypes">
<RequestContext xmlns="http://www.swissdec.ch/schema/sd/20090803/SalaryDeclarationContainer">
<UserAgent xmlns=""/>
<CompanyName xmlns=""/>
</RequestContext>
</DeclareSalary>
What can I do that these empty attributes will not occur? Does anybody has a idea?
No, i cannot create it with XML-Ports.... the code is to complex to simly use an xml port.
Thanks
Patrick
0
Comments
-
Can you show us the code where you are exporting
<UserAgent xmlns=""/>
<CompanyName xmlns=""/>
these attributes?0 -
Sure... here is the code:
IF cNamespaceIn <> '' THEN BEGIN
rNameSpaceLoc.GET(cNamespaceIn);
autElementVar := autXMLDoc.createNode(1,tNameIn,rNameSpaceLoc.URI);
END ELSE
autElementVar := autXMLDoc.createNode(1,tNameIn,'');
IF tDataIn <> '' THEN
autElementVar.text := tDataIn;
autParentIn.appendChild(autElementVar);
In this case the value in tDataIn is always empty... so only the functions createNode and appendChild will be called.0 -
If you dont want to create with empty value try with
IF tDataIn <> '' THEN BEGIN autElementVar.text := tDataIn; autParentIn.appendChild(autElementVar); END;
0 -
mohana_cse06 wrote:If you dont want to create with empty value try with
IF tDataIn <> '' THEN BEGIN autElementVar.text := tDataIn; autParentIn.appendChild(autElementVar); END;
That's not possible, because I need this element... but not the empty attribute.0 -
I just found something very interessting:
The original code to set the attribut looks like this:
IF rLineIn.Namespace <> '' THEN BEGIN
rNameSpaceLoc.GET(rLineIn.Namespace);
tAttrNameLoc := 'xmlns';
autParentIn.setAttribute(tAttrNameLoc,rNameSpaceLoc.URI);
CLEAR(rNameSpaceLoc);
END;
this creates the following XML-File:
<DeclareSalary xmlns="http://www.swissdec.ch/schema/sd/20090803/SalaryDeclarationServiceTypes">
<RequestContext xmlns="http://www.swissdec.ch/schema/sd/20090803/SalaryDeclarationContainer">
<UserAgent xmlns="">
<Producer>Microsoft Corporation</Producer>
<Name>Microsoft Dynamics NAV</Name>
But if I change the code like this:
IF rLineIn.Namespace <> '' THEN BEGIN
rNameSpaceLoc.GET(rLineIn.Namespace);
tAttrNameLoc := 'xmlnsx';
autParentIn.setAttribute(tAttrNameLoc,rNameSpaceLoc.URI);
CLEAR(rNameSpaceLoc);
END;
the XML-File looks like this:
<DeclareSalary xmlnsx="http://www.swissdec.ch/schema/sd/20090803/SalaryDeclarationServiceTypes">
<RequestContext xmlnsx="http://www.swissdec.ch/schema/sd/20090803/SalaryDeclarationContainer">
<UserAgent>
<Producer>Microsoft Corporation</Producer>
<Name>Microsoft Dynamics NAV</Name>
This will be how it looks like, with exception of the attribut
Patrick0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions