Topic: Coldfusion Xml Namespace


luteralus    -- 07-05-2013 @ 7:07 AM
  I need to build an xml document with a namespace. When
I create the root element, I define all the necessary
namespaces with xmlAttribute[xmlns:xxx]. But after
that, when I create a child element the namespace
reference is also shown.Is this ok or what do I need to
prevent that?
Here is my code example
y_doc = XmlNew();
my_doc.xmlRoot = XmlElemNew(my_doc,"Invoice");
my_doc.xmlRoot.XmlAttributes["xmlns"] =
'urn:oasis:names:specification:ubl:schema:xsd:Invoice-
2';
    my_doc.xmlRoot.XmlAttributes["xmlns:cbc"] =
'urn:oasis:names:specification:ubl:schema:xsd:CommonBas
icComponents-2';
    my_doc.Invoice.XmlChildren[1] =
XmlElemNew(my_doc,"cbc:UBLVersionID");
    my_doc.Invoice.XmlChildren[1].XmlText = '2.0';

and result is
<?xml version="1.0" encoding="UTF-8"?>
<Invoice
xmlns="urn:oasis:names:specification:ubl:schema:xsd:Inv
oice-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd
:CommonBasicComponents-2">
    <cbc:UBLVersionID
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd
:CommonBasicComponents-2">2.0</cbc:UBLVersionID>
</Invoice>

But i want to be seen as
<cbc:UBLVersionID>2.0</cbc:UBLVersionID>

Thanks


Webmaster    -- 08-09-2013 @ 1:25 PM
  I see you created a namespace, but you never defined
the namespace in the header.

<?xml version="1.0" encoding="UTF-8" cbc="PATH?"
?>
<Invoice
xmlns="urn:oasis:names:specification:ubl:schema:xsd:Inv

oice-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd

:CommonBasicComponents-2">

Pablo Varando
Senior Application Architect
EasyCFM.COM, LLC.

904.483.1457 \\ mobile
webmaster@easycfm.com \\email

\m/ (>.<) \m/
--- rock on ---


EasyCFM.COM ColdFusion Forums : http://archive.easycfm.com/forums
Topic: http://archive.easycfm.com/forums/viewmessages.cfm?Forum=12&Topic=15329