I used the XML Data Binding Wizard to create a class for an IRS XML specification file. I'm having two problems that I can't find an answer for (and I have spent hours trying).
This is a snippet of the XML output that I need:
<?xml version="1.0" encoding="UTF-8"?>
<h1:ACAUIBusinessHeader xmlns="urn:us:gov:treasury:irs:ext:aca:air:7.0" xmlns:irs="urn:us:gov:treasury:irs:common" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:acabushdr="urn:us:gov:treasury:irs:msg:acabusinessheader" xmlns:h1="urn:us:gov:treasury:irs:msg:acauibusinessheader" xsi:schemaLocation="urn:us:gov:treasury:irs:msg:acauibusinessheader IRS-ACAUserInterfaceHeaderMessage.xsd">
<acabushdr:ACABusinessHeader>
<UniqueTransmissionId>00000000-0000-0000-0000-000000000000:SYS12:BB000::T</UniqueTransmissionId>
<irs:Timestamp>2001-12-17T09:30:47Z</irs:Timestamp>
</acabushdr:ACABusinessHeader>
<ACATransmitterManifestReqDtl>
<PaymentYr>1000</PaymentYr>
<PriorYearDataInd>1</PriorYearDataInd>
<irs:EIN>000000000</irs:EIN>
</ACATransmitterManifestReqDtl>
</h1:ACATransmitterManifestReqDtl>
As you can see the root node does not use the default xmlns namespace. If I add the "h1:" prefix to the name in GetDocBinding() calls then it adds the "h1:" prefix to ALL the child nodes which is NOT what I need.
Also I manually edited the class that the data binding wizard created so that I can define the extra namespaces using the DeclareNamespace() method. Yet when I try to use the optional third parameter of the RegisterChildNode() method to define the URI, it crashes when I try to use the property for that node.
Here's a code snippet of the edited class:
_di_IXMLTransmitterACAUIBusinessHeaderType __fastcall GetACAUIBusinessHeader(Xml::Xmlintf::_di_IXMLDocument Doc)
{
return (_di_IXMLTransmitterACAUIBusinessHeaderType) Doc->GetDocBinding("ACAUIBusinessHeader", __classid(TXMLTransmitterACAUIBusinessHeaderType), eACA_UI_Header_TargetNamespace);
};
_di_IXMLTransmitterACAUIBusinessHeaderType __fastcall GetACAUIBusinessHeader(Xml::Xmldoc::TXMLDocument *Doc)
{
Xml::Xmlintf::_di_IXMLDocument DocIntf;
Doc->GetInterface(DocIntf);
return GetACAUIBusinessHeader(DocIntf);
};
_di_IXMLTransmitterACAUIBusinessHeaderType __fastcall LoadACAUIBusinessHeader(const System::UnicodeString& FileName)
{
return (_di_IXMLTransmitterACAUIBusinessHeaderType) Xml::Xmldoc::LoadXMLDocument(FileName)->GetDocBinding("ACAUIBusinessHeader", __classid(TXMLTransmitterACAUIBusinessHeaderType), eACA_UI_Header_TargetNamespace);
};
_di_IXMLTransmitterACAUIBusinessHeaderType __fastcall NewACAUIBusinessHeader()
{
return (_di_IXMLTransmitterACAUIBusinessHeaderType) Xml::Xmldoc::NewXMLDocument()->GetDocBinding("ACAUIBusinessHeader", __classid(TXMLTransmitterACAUIBusinessHeaderType), eACA_UI_Header_TargetNamespace);
};
// TXMLTransmitterACAUIBusinessHeaderType
void __fastcall TXMLTransmitterACAUIBusinessHeaderType::AfterConstruction(void)
{
RegisterChildNode(System::UnicodeString("ACABusinessHeader"), __classid(TXMLACABulkBusinessHeaderRequestType_air7_0), "urn:us:gov:treasury:irs:common");
RegisterChildNode(System::UnicodeString("ACATransmitterManifestReqDtl"), __classid(TXMLACATrnsmtManifestReqDtlType_air7_0));
Xml::Xmldoc::TXMLNode::AfterConstruction();
};
UnicodeString __fastcall TXMLTransmitterACAUIBusinessHeaderType::Get_irs_NS()
{
return TXMLNode::AttributeNodes->Nodes[UnicodeString("xmlns:irs")]->Text;
};
void __fastcall TXMLTransmitterACAUIBusinessHeaderType::Set_irs_NS(UnicodeString Value)
{
//TXMLNode::SetAttributeNS(UnicodeString("xmlns:irs"), "", Value);
TXMLNode::DeclareNamespace(UnicodeString("irs"), Value);
};
// More of the same
And here is some preliminary code I wrote to test the output using the class:
Manifest = new TXMLDocument(GetWindow());
Manifest->DOMVendor = GetDOMVendor("MSXML"); // NOT cross platform compatible
Manifest->NodeIndentStr = char(9); // TAB character
Manifest->Options = Manifest->Options << doNodeAutoIndent << doAttrNull << doAutoPrefix;
Manifest_root = GetACAUIBusinessHeader(Manifest);
Manifest->Version = "1.0";
Manifest->Encoding = "UTF-8";
// Assign NameSpaces and Schema
Manifest_root->irs_NS = "urn:us:gov:treasury:irs:common";
Manifest_root->xsi_NS = "http://www.w3.org/2001/XMLSchema-instance";
Manifest_root->acabushdr_NS = "urn:us:gov:treasury:irs:msg:acabusinessheader";
Manifest_root->h1_NS = "urn:us:gov:treasury:irs:msg:acauibusinessheader";
Manifest_root->schemaLocation = "urn:us:gov:treasury:irs:msg:acauibusinessheader IRS-ACAUserInterfaceHeaderMessage.xsd";
Manifest_root->ACABusinessHeader->UniqueTransmissionId = "token"; // Just for testing
Manifest_root->ACABusinessHeader->Timestamp = "2001-12-17T09:30:47Z"; // Just for testing
Manifest_root->ACATransmitterManifestReqDtl->PaymentYr = "2016";
Manifest_root->ACATransmitterManifestReqDtl->PriorYearDataInd = "1";
Manifest_root->ACATransmitterManifestReqDtl->EIN = "000000000";
If I take out the third parameter for the RegisterChildNode() method in the code above it doesn't crash but the output isn't correct:
<?xml version="1.0" encoding="UTF-8"?>
<ACAUIBusinessHeader xmlns="urn:us:gov:treasury:irs:ext:aca:air:7.0" xmlns:irs="urn:us:gov:treasury:irs:common" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:acabushdr="urn:us:gov:treasury:irs:msg:acabusinessheader" xmlns:h1="urn:us:gov:treasury:irs:msg:acauibusinessheader" xsi:schemaLocation="urn:us:gov:treasury:irs:msg:acauibusinessheader IRS-ACAUserInterfaceHeaderMessage.xsd">
<ACABusinessHeader>
<UniqueTransmissionId>token</UniqueTransmissionId>
<Timestamp>2001-12-17T09:30:47Z</Timestamp>
</ACABusinessHeader>
<ACATransmitterManifestReqDtl>
<PaymentYr>2016</PaymentYr>
<PriorYearDataInd>1</PriorYearDataInd>
<EIN>000000000</EIN>
</ACATransmitterManifestReqDtl>
</ACAUIBusinessHeader>
As you can see the prefixes (namespaces) I need for the root node ACAUIBusinessHeader, the ACABusinessHeader node, and the Timestamp & EIN nodes are missing, and I don't know how to properly adapt the class to assign them.