Copy link to clipboard
Copied
Hi,
I am trying to obtain information inside the XML file Testff.xml.
Below is the contents of the XML file:
<?xml version="1.0" encoding="UTF-8"?>
<NotesImport xsi:noNamespaceSchemaLocation="G:/USERS/user uploading id/BUSFIL~1/logNotesImportv2.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Facility>
<FacilityID>8</FacilityID>
<FacilityName>THE x</FacilityName>
<DateDataExtracted>2015-05-05</DateDataExtracted>
<TimeDataExtracted>23:55:00</TimeDataExtracted>
<LogNote>
<SSN>000-00-0000</SSN>
<LogNoteID>20150505065022</LogNoteID>
<DateContacted>2015-05-05</DateContacted>
<DateEntered>2015-05-05</DateEntered>
<WhoContacted>21</WhoContacted>
<ContactType>114</ContactType>
<Confidential>F</Confidential>
<InputWorker>jhjh67</InputWorker>
<Description>The Service Plan was revised</Description>
<LogNoteUnit>2</LogNoteUnit>
</LogNote>
<LogNote>
<SSN>000-00-0000</SSN>
<LogNoteID>201505050650232</LogNoteID>
<DateContacted>2015-05-03</DateContacted>
<DateEntered>2015-05-03</DateEntered>
<WhoContacted>23</WhoContacted>
<ContactType>113</ContactType>
<Confidential>F</Confidential>
<InputWorker>jhj3</InputWorker>
<Description>The revised</Description>
<LogNoteUnit>3</LogNoteUnit>
</LogNote>
</Facility>
</NotesImport>
When trying to read the file, the XML attributes are not in the file output.
I am trying to get the value for the LogNoteID.
Below is the code being used.
<cffile action="read" file="D:\CFMISC\Bus\Testff.xml" variable="MyXmlCode">
<CFSET MyXml = XmlParse(MyXmlCode)>
<CFSET xnCompany = MyXML.XmlRoot>
#xnCompany#
<CFSET sCompanyName = xnCompany.XmlAttributes["LogNoteID"]>
Output of the xnCompany value:
8 THE x 2015-05-05 23:55:00 000-00-0000 20150505065022 2015-05-05 2015-05-05 21 114 F jhjh67 The Service Plan was revised 2 000-00-0000 201505050650232 2015-05-03 2015-05-03 23 113 F jhj3 The revised 3
When I tried to access the LogNoteID, I am receiving the message,
Element LogNoteID is undefined in a Java object of type class coldfusion.xml.XmlAttrMap.
How would the XML attributes appear in the output and how to access the LogNoteID value?
Thanks,
Mike
Copy link to clipboard
Copied
Firstly, there are no attributes at all, in the XML you posted.
Secondly, LogNoteID is not an element of the root element. Why are you trying to access it on the root element?
Cheers
Eddie
Copy link to clipboard
Copied
As already mentioned, your misusing the xml document. Look at xmlSearch. There are some good examples around and it's easy once you get the hang of it. If the doc examples aren't detailed enough, google "coldfusion xmlsearch".
Copy link to clipboard
Copied
userCold9 wrote
...I am trying to get the value for the LogNoteID.
...
How would the XML attributes appear in the output and how to access the LogNoteID value?
The element you have defined, xnCompany, places you at the document root. That is, at the element NotesImport.
Then the question is how to get to LogNoteID from there. An answer: by navigating through Facility and each of its two LogNote children. The respective values are:
xnCompany['Facility']['LogNote'][1]['LogNoteID'].xmlText
xnCompany['Facility']['LogNote'][2]['LogNoteID'].xmlText