0

我正在尝试在我以 id 属性为目标的元素中编写新元素

这是 XML:

<?xml version="1.0" encoding="UTF-8"?>
<webpages>
  <course id="fteCharts">
    <linkName>FTE Charts</linkName>
    <link>index.cfm</link>
    <linkInfo>Looking for a new job or rotational experience, the links to NRC Jobs, solicitations of interest and rotational opportunities are provided. Would you like to become a leader in the NRC. The NRC offers a number of leadership development programs. The Leadership Development link provides you a list of these programs.</linkInfo>
  </course>
  <course id="matrix">
    <linkName>Skills Matrix</linkName>
    <link>index.cfm</link>
    <linkInfo>Skills Matrix Link. The NRC offers a number of leadership development programs. The Leadership Development link provides you a list of these programs.</linkInfo>
    <subLink>
        <name>Adminstrator Tool Kit 2</name>
        <url>http://r2.nrc.gov/drs/careertools/admintoolkit.pdf</url>
    </subLink>
    <subLink>
        <name>Technical Tool Kit Matrix 2</name>
        <url>http://r2.nrc.gov/drs/careertools/technicaltoolkit.pdf</url>
    </subLink>
  </course>
</webpages>

以下是我如何在我的 cfc 中提取此元素的数据:

<cfset params = toString( getHttpRequestData().content ) />

<cfset args = #deserializeJSON(params)# />

<cfset bPath = "e:\webapps\NRCNewsApps\rmsi" />

<cffile action="read" file="#bPath#\xml\nav.xml" variable="myxml">  
<cfset thedoc = XmlParse(myxml)>

<cfset arynode = XmlSearch(thedoc, "/webpages/course[ @id = '#args.linkID#' ]") />
<cfset xmlCourse = arynode[1] />

然后返回我xmlCourse想要添加节点的课程。它是一个包含我需要的 xml 数据的数组:

XmlElemNew(xmlCourse, "subLink");

我想在目标课程中创建新的空白 xml 节点(名为“子链接”),我一直在尝试一整天但还没有弄清楚。

4

1 回答 1

0

You would have to save the xml file to your ram or to disk the read it and search the saved document and attach the nodes by reading the data and appending them using file and append commands. I am not sure why you would want to insert empty nodes. What are you trying to accomplish? But there are CFC files also that will read xml and convert it to a struct I have used it before but never found any real practical application for using it.

于 2013-10-24T05:20:06.230 回答