问题
I'm trying to insert an attribute into the root node of an XML fragment in loadrunner, using the lr_xml_insert function.
Code Fragment:
char *inputXML=
     "<a>" 
        "<b>" 
            "<c></c>"
        "</b>"
     "</a>";
lr_save_string(inputXML,"paramInputXML");
lr_xml_insert("Xml={paramInputXML}",
              "Query=/a",
              "ResultParam=Result",
              "Position=attribute",
              "XmlFragment=attribValue=\"0\"",
              LAST);
lr_output_message(lr_eval_string("String after insertion: {Result}"));
Desired output:
String after insertion: <a attribValue="0"><b><c/></b></a>
Actual Loadrunner output
String after insertion: <a><b><c/></b>attribValue="0"</a>
The function behaves as expected if the xpath query is /a/b or /a/b/c instead of /a
回答1:
I checked the issue within the product code (12.01) and it seems to be a product issue specific to this case. It seems that when the root element is selected it automatically changes the Position argument to 'child'. I have opened a defect in our internal systems.
Thank you very much for finding this issue.
来源:https://stackoverflow.com/questions/25509383/how-to-insert-an-attribute-into-xml-root-node-in-loadrunner-using-lr-xml-insert