Jump to content

Recommended Posts

Posted (edited)

Actually, I was wrong. 'Last()' did not solve it, but it looked like it did. It doesn't seem to be completely reliable, and I would occasionally end up with 'clusters' of file names within one file tag. Not sure why, could be a bug, but I don't know who's.

I ended up having to set 'id' attributes for everything, then use XPaths like this (quite ugly, but such is life):

"/Project/File[@id='" & $i & "']"

"/Project/File[@id='" & $i & "']/Function[@id='" & $funcs & "']"

Edited by aGorilla
Posted

Actually, I was wrong. 'Last()' did not solve it, but it looked like it did. It doesn't seem to be completely reliable, and I would occasionally end up with 'clusters' of file names within one file tag. Not sure why, could be a bug, but I don't know who's.

I ended up having to set 'id' attributes for everything, then use XPaths like this (quite ugly, but such is life):

"/Project/File[@id='" & $i & "']"

"/Project/File[@id='" & $i & "']/Function[@id='" & $funcs & "']"

Did you try it like this?

#include <_XMLDomWrapper.au3>
Local $XML = "project.xml"
Local $oXml = _XMLFileOpen ($XML)

If @error Then
    MsgBox(0, "Error", "There was an error opening the file.")
    Exit
 EndIf
 $ret =_XMLCreateChildNode("project","file")
If @error Then ConsoleWrite(_XMLError()&@lf)
 $ret =_XMLCreateChildNode("project/file[last()]","name","anotherfile.ext")
If @error Then ConsoleWrite(_XMLError()&@lf)
$oXml = 0
Posted (edited)

Not yet, but I will. Althought the XML noob in me has grown to like the 'id's, I can't screw them up :)

While I'm here, another XML noob question... Are empty tags valid, and is it easy to test for their presence?

I'm working my way down to /Project/File/Function/Parameter, and I have a 'name' tag, but I also want a 'default' tag. A lot of parameters default to "" (an empty string), so should I use <Default>""</Default>, or is it ok to just use <Default></Default> (which is what I prefer to use)?

ps: I'm hoping to post my code soon, I'm trying to use XML to build a system tray menu that displays an api. Here's the prototype for the XML:

<Project>
  <Name></Name>
  <Note></Note>
  <Tray>want to put tray settings - icons, colors, etc. here.</Tray>  
  <File id="#">
    <Name></Name>
    <Note></Note>
    <Function id="#">
      <Name></Name>
      <Note></Note>
      <Parameter id="#">
        <Name></Name>
        <Note></Note>
        <Default></Default>
        <Reference></Reference>
      </Parameter>
    </Function>
  </File>
</Project>

I'm using your docs as an example (they were small enough to start with, and covered the bases - having default values, and a couple of 'ByRef's). Here they are, in XML form:

<Project>
  <Name>XMLDomWrapper</Name>

  <File id="1">
    <Name>_XMLDomWrapper.au3</Name>
    <Note></Note>

    <Function id="1">
      <Name>_XMLCreateFile</Name>
      <Parameter id="1">
        <Name>sPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>sRootNode</Name>
      </Parameter>
      <Parameter id="3">
        <Name>bOverwrite</Name>
        <Default>False</Default>
      </Parameter>
      <Note>Creates an XML file with the given name and root.</Note>
    </Function>

    <Function id="2">
      <Name>_XMLFileOpen</Name>
      <Parameter id="1">
        <Name>sXMLFile</Name>
      </Parameter>
      <Parameter id="2">
        <Name>sNamespace</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="3">
        <Name>ver</Name>
        <Default>-1</Default>
      </Parameter>
      <Note>Creates an instance of an XML file.</Note>
    </Function>

    <Function id="3">
      <Name>_XMLGetChildNodes</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Note>Selects XML child Node(s) of an element based on XPath input from root node.</Note>
    </Function>

    <Function id="4">
      <Name>_XMLGetNodeCount</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strQry</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="3">
        <Name>iNodeType</Name>
        <Default>1</Default>
      </Parameter>
      <Note>Get node count for specified path and type.</Note>
    </Function>

    <Function id="5">
      <Name>_XMLGetPath</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Note>Returns a nodes full path based on XPath input from root node.</Note>
    </Function>

    <Function id="6">
      <Name>_XMLSelectNodes</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
        <Default></Default>
        <Reference></Reference>
      </Parameter>
      <Note>Selects XML Node(s) based on XPath input from root node.</Note>
    </Function>

    <Function id="7">
      <Name>_XMLGetField</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Note>Get XML Field(s) based on XPath input from root node.</Note>
    </Function>

    <Function id="8">
      <Name>_XMLGetValue</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Note>Get XML Field based on XPath input from root node.</Note>
    </Function>

    <Function id="9">
      <Name>_XMLGetChildText</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Note>Selects XML child Node(s) of an element based on XPath input from root node.</Note>
    </Function>

    <Function id="10">
      <Name>_XMLUpdateField</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strData</Name>
      </Parameter>
      <Note>Update existing node(s) based on XPath specs.</Note>
    </Function>

    <Function id="11">
      <Name>_XMLReplaceChild</Name>
      <Parameter id="1">
        <Name>objOldNode</Name>
      </Parameter>
      <Parameter id="2">
        <Name>objNewNode</Name>
      </Parameter>
      <Parameter id="3">
        <Name>ns</Name>
        <Default></Default>
      </Parameter>
      <Note>Replaces a node with a new node.</Note>
    </Function>

    <Function id="12">
      <Name>_XMLDeleteNode</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Note>Delete specified XPath node.</Note>
    </Function>

    <Function id="13">
      <Name>_XMLDeleteAttr</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strAttrib</Name>
      </Parameter>
      <Note>Delete attribute for specified XPath</Note>
    </Function>

    <Function id="14">
      <Name>_XMLDeleteAttrNode</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strAttrib</Name>
      </Parameter>
      <Note>Delete attribute node for specified XPath</Note>
    </Function>

    <Function id="15">
      <Name>_XMLGetAttrib</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strAttrib</Name>
      </Parameter>
      <Parameter id="3">
        <Name>strQuery</Name>
        <Default></Default>
      </Parameter>
      <Note>Get XML attribute based on XPath input from root node.</Note>
    </Function>

    <Function id="16">
      <Name>_XMLGetAllAttrib</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="2">
        <Name>aName</Name>
        <Reference>True</Reference>
      </Parameter>
      <Parameter id="3">
        <Name>aValue</Name>
        <Reference>True</Reference>
      </Parameter>
      <Parameter id="4">
        <Name>strQry</Name>
        <Default></Default>
      </Parameter>
      <Note>Get all XML Field(s) attributes based on XPath input from root node.</Note>
    </Function>

    <Function id="17">
      <Name>_XMLGetAllAttribIndex</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="2">
        <Name>aName</Name>
        <Reference>True</Reference>
      </Parameter>
      <Parameter id="3">
        <Name>aValue</Name>
        <Reference>True</Reference>
      </Parameter>
      <Parameter id="4">
        <Name>strQry</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="5">
        <Name>NodeIndex</Name>
        <Default>0</Default>
      </Parameter>
      <Note>Get all XML Field(s) attributes based on Xpathn and specific index.</Note>
    </Function>

    <Function id="18">
      <Name>_XMLSetAttrib</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strAttrib</Name>
      </Parameter>
      <Parameter id="3">
        <Name>strValue</Name>
        <Default></Default>
      </Parameter>
      <Note>Set XML Field(s) attributes based on XPath input from root node.</Note>
    </Function>

    <Function id="19">
      <Name>_XMLCreateCDATA</Name>
      <Parameter id="1">
        <Name>strNode</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strCDATA</Name>
      </Parameter>
      <Parameter id="3">
        <Name>strNameSpc</Name>
        <Default></Default>
      </Parameter>
      <Note>Create a CDATA SECTION node directly under root.</Note>
    </Function>

    <Function id="20">
      <Name>_XMLCreateComment</Name>
      <Parameter id="1">
        <Name>strNode</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strComment</Name>
      </Parameter>
      <Note>Create a COMMENT node at specified path.</Note>
    </Function>

    <Function id="21">
      <Name>_XMLCreateAttrib</Name>
      ( strXPath,,="" )
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strAttrName</Name>
      </Parameter>
      <Parameter id="3">
        <Name>strAttrValue</Name>
        <Default></Default>
      </Parameter>
      <Note>Creates an attribute for the specified node.</Note>
    </Function>

    <Function id="22">
      <Name>_XMLCreateRootChild</Name>
      <Parameter id="1">
        <Name>strNode</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strData</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="3">
        <Name>strNameSpc</Name>
        <Default></Default>
      </Parameter>
      <Note>Create node directly under root.</Note>
    </Function>

    <Function id="23">
      <Name>_XMLCreateRootNodeWAttr</Name>
      <Parameter id="1">
        <Name>strNode</Name>
      </Parameter>
      <Parameter id="2">
        <Name>aAttr</Name>
      </Parameter>
      <Parameter id="3">
        <Name>aVal</Name>
      </Parameter>
      <Parameter id="4">
        <Name>strData</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="5">
        <Name>strNameSpc</Name>
        <Default></Default>
      </Parameter>
      <Note>Create a child node under root node with attributes.</Note>
    </Function>

    <Function id="24">
      <Name>_XMLCreateChildNode</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strNode</Name>
      </Parameter>
      <Parameter id="3">
        <Name>strData</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="4">
        <Name>strNameSpc</Name>
        <Default></Default>
      </Parameter>
      <Note>Create a child node under the specified XPath Node.</Note>
    </Function>

    <Function id="25">
      <Name>_XMLCreateChildWAttr</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strNode</Name>
      </Parameter>
      <Parameter id="3">
        <Name>aAttr</Name>
      </Parameter>
      <Parameter id="4">
        <Name>aVal</Name>
      </Parameter>
      <Parameter id="5">
        <Name>strData</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="6">
        <Name>strNameSpc</Name>
        <Default></Default>
      </Parameter>
      <Note>Create a child node under the specified XPath Node with Attributes.</Note>
    </Function>

    <Function id="26">
      <Name>_XMLSchemaValidate</Name>
      <Parameter id="1">
        <Name>sXMLFile</Name>
      </Parameter>
      <Parameter id="2">
        <Name>ns</Name>
      </Parameter>
      <Parameter id="3">
        <Name>sXSDFile</Name>
      </Parameter>
      <Note>Validate a document against a DTD.</Note>
    </Function>

    <Function id="27">
      <Name>_XMLGetDomVersion</Name>
      <Note>Returns the XSXML version currently in use.</Note>
    </Function>

    <Function id="28">
      <Name>_XMLError</Name>
      <Parameter id="1">
        <Name>sError</Name>
        <Default></Default>
      </Parameter>
      <Note>Sets or Gets XML error message generated by XML functions.</Note>
    </Function>

    <Function id="29">
      <Name>_XMLUDFVersion</Name>
      <Note>Returns the UDF Version number.</Note>
    </Function>

    <Function id="30">
      <Name>_XMLTransform</Name>
      <Parameter id="1">
        <Name>oXMLDoc</Name>
        <Default></Default>
        <Reference></Reference>
      </Parameter>
      <Parameter id="2">
        <Name>Style</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="3">
        <Name>szNewDoc</Name>
        <Default></Default>
      </Parameter>
      <Note>Transfroms the document using built-in sheet or xsl file passed to function.</Note>
    </Function>

    <Function id="31">
      <Name>_XMLNodeExists</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Note>Checks for the existence of the specified path.</Note>
    </Function>
  </File>
</Project>

Edit: fixed a couple of id's, and other silly things.

Edited by aGorilla
Posted

Not yet, but I will. Althought the XML noob in me has grown to like the 'id's, I can't screw them up :)

While I'm here, another XML noob question... Are empty tags valid, and is it easy to test for their presence?

I'm working my way down to /Project/File/Function/Parameter, and I have a 'name' tag, but I also want a 'default' tag. A lot of parameters default to "" (an empty string), so should I use <Default>""</Default>, or is it ok to just use <Default></Default> (which is what I prefer to use)?

ps: I'm hoping to post my code soon, I'm trying to use XML to build a system tray menu that displays an api. Here's the prototype for the XML:

<Project>
  <Name></Name>
  <Note></Note>
  <Tray>want to put tray settings - icons, colors, etc. here.</Tray>  
  <File id="#">
    <Name></Name>
    <Note></Note>
    <Function id="#">
      <Name></Name>
      <Note></Note>
      <Parameter id="#">
        <Name></Name>
        <Note></Note>
        <Default></Default>
        <Reference></Reference>
      </Parameter>
    </Function>
  </File>
</Project>

I'm using your docs as an example (they were small enough to start with, and covered the bases - having default values, and a couple of 'ByRef's). Here they are, in XML form:

<Project>
  <Name>XMLDomWrapper</Name>

  <File id="1">
    <Name>_XMLDomWrapper.au3</Name>
    <Note></Note>

    <Function id="1">
      <Name>_XMLCreateFile</Name>
      <Parameter id="1">
        <Name>sPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>sRootNode</Name>
      </Parameter>
      <Parameter id="3">
        <Name>bOverwrite</Name>
        <Default>False</Default>
      </Parameter>
      <Note>Creates an XML file with the given name and root.</Note>
    </Function>

    <Function id="2">
      <Name>_XMLFileOpen</Name>
      <Parameter id="1">
        <Name>sXMLFile</Name>
      </Parameter>
      <Parameter id="2">
        <Name>sNamespace</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="3">
        <Name>ver</Name>
        <Default>-1</Default>
      </Parameter>
      <Note>Creates an instance of an XML file.</Note>
    </Function>

    <Function id="3">
      <Name>_XMLGetChildNodes</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Note>Selects XML child Node(s) of an element based on XPath input from root node.</Note>
    </Function>

    <Function id="4">
      <Name>_XMLGetNodeCount</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strQry</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="3">
        <Name>iNodeType</Name>
        <Default>1</Default>
      </Parameter>
      <Note>Get node count for specified path and type.</Note>
    </Function>

    <Function id="5">
      <Name>_XMLGetPath</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Note>Returns a nodes full path based on XPath input from root node.</Note>
    </Function>

    <Function id="6">
      <Name>_XMLSelectNodes</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
        <Default></Default>
        <Reference></Reference>
      </Parameter>
      <Note>Selects XML Node(s) based on XPath input from root node.</Note>
    </Function>

    <Function id="7">
      <Name>_XMLGetField</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Note>Get XML Field(s) based on XPath input from root node.</Note>
    </Function>

    <Function id="8">
      <Name>_XMLGetValue</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Note>Get XML Field based on XPath input from root node.</Note>
    </Function>

    <Function id="9">
      <Name>_XMLGetChildText</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Note>Selects XML child Node(s) of an element based on XPath input from root node.</Note>
    </Function>

    <Function id="10">
      <Name>_XMLUpdateField</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strData</Name>
      </Parameter>
      <Note>Update existing node(s) based on XPath specs.</Note>
    </Function>

    <Function id="11">
      <Name>_XMLReplaceChild</Name>
      <Parameter id="1">
        <Name>objOldNode</Name>
      </Parameter>
      <Parameter id="2">
        <Name>objNewNode</Name>
      </Parameter>
      <Parameter id="3">
        <Name>ns</Name>
        <Default></Default>
      </Parameter>
      <Note>Replaces a node with a new node.</Note>
    </Function>

    <Function id="12">
      <Name>_XMLDeleteNode</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Note>Delete specified XPath node.</Note>
    </Function>

    <Function id="13">
      <Name>_XMLDeleteAttr</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strAttrib</Name>
      </Parameter>
      <Note>Delete attribute for specified XPath</Note>
    </Function>

    <Function id="14">
      <Name>_XMLDeleteAttrNode</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strAttrib</Name>
      </Parameter>
      <Note>Delete attribute node for specified XPath</Note>
    </Function>

    <Function id="15">
      <Name>_XMLGetAttrib</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strAttrib</Name>
      </Parameter>
      <Parameter id="3">
        <Name>strQuery</Name>
        <Default></Default>
      </Parameter>
      <Note>Get XML attribute based on XPath input from root node.</Note>
    </Function>

    <Function id="16">
      <Name>_XMLGetAllAttrib</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="2">
        <Name>aName</Name>
        <Reference>True</Reference>
      </Parameter>
      <Parameter id="3">
        <Name>aValue</Name>
        <Reference>True</Reference>
      </Parameter>
      <Parameter id="4">
        <Name>strQry</Name>
        <Default></Default>
      </Parameter>
      <Note>Get all XML Field(s) attributes based on XPath input from root node.</Note>
    </Function>

    <Function id="17">
      <Name>_XMLGetAllAttribIndex</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="2">
        <Name>aName</Name>
        <Reference>True</Reference>
      </Parameter>
      <Parameter id="3">
        <Name>aValue</Name>
        <Reference>True</Reference>
      </Parameter>
      <Parameter id="4">
        <Name>strQry</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="5">
        <Name>NodeIndex</Name>
        <Default>0</Default>
      </Parameter>
      <Note>Get all XML Field(s) attributes based on Xpathn and specific index.</Note>
    </Function>

    <Function id="18">
      <Name>_XMLSetAttrib</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strAttrib</Name>
      </Parameter>
      <Parameter id="3">
        <Name>strValue</Name>
        <Default></Default>
      </Parameter>
      <Note>Set XML Field(s) attributes based on XPath input from root node.</Note>
    </Function>

    <Function id="19">
      <Name>_XMLCreateCDATA</Name>
      <Parameter id="1">
        <Name>strNode</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strCDATA</Name>
      </Parameter>
      <Parameter id="3">
        <Name>strNameSpc</Name>
        <Default></Default>
      </Parameter>
      <Note>Create a CDATA SECTION node directly under root.</Note>
    </Function>

    <Function id="20">
      <Name>_XMLCreateComment</Name>
      <Parameter id="1">
        <Name>strNode</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strComment</Name>
      </Parameter>
      <Note>Create a COMMENT node at specified path.</Note>
    </Function>

    <Function id="21">
      <Name>_XMLCreateAttrib</Name>
      ( strXPath,,="" )
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strAttrName</Name>
      </Parameter>
      <Parameter id="3">
        <Name>strAttrValue</Name>
        <Default></Default>
      </Parameter>
      <Note>Creates an attribute for the specified node.</Note>
    </Function>

    <Function id="22">
      <Name>_XMLCreateRootChild</Name>
      <Parameter id="1">
        <Name>strNode</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strData</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="3">
        <Name>strNameSpc</Name>
        <Default></Default>
      </Parameter>
      <Note>Create node directly under root.</Note>
    </Function>

    <Function id="23">
      <Name>_XMLCreateRootNodeWAttr</Name>
      <Parameter id="1">
        <Name>strNode</Name>
      </Parameter>
      <Parameter id="2">
        <Name>aAttr</Name>
      </Parameter>
      <Parameter id="3">
        <Name>aVal</Name>
      </Parameter>
      <Parameter id="4">
        <Name>strData</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="5">
        <Name>strNameSpc</Name>
        <Default></Default>
      </Parameter>
      <Note>Create a child node under root node with attributes.</Note>
    </Function>

    <Function id="24">
      <Name>_XMLCreateChildNode</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strNode</Name>
      </Parameter>
      <Parameter id="3">
        <Name>strData</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="4">
        <Name>strNameSpc</Name>
        <Default></Default>
      </Parameter>
      <Note>Create a child node under the specified XPath Node.</Note>
    </Function>

    <Function id="25">
      <Name>_XMLCreateChildWAttr</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Parameter id="2">
        <Name>strNode</Name>
      </Parameter>
      <Parameter id="3">
        <Name>aAttr</Name>
      </Parameter>
      <Parameter id="4">
        <Name>aVal</Name>
      </Parameter>
      <Parameter id="5">
        <Name>strData</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="6">
        <Name>strNameSpc</Name>
        <Default></Default>
      </Parameter>
      <Note>Create a child node under the specified XPath Node with Attributes.</Note>
    </Function>

    <Function id="26">
      <Name>_XMLSchemaValidate</Name>
      <Parameter id="1">
        <Name>sXMLFile</Name>
      </Parameter>
      <Parameter id="2">
        <Name>ns</Name>
      </Parameter>
      <Parameter id="3">
        <Name>sXSDFile</Name>
      </Parameter>
      <Note>Validate a document against a DTD.</Note>
    </Function>

    <Function id="27">
      <Name>_XMLGetDomVersion</Name>
      <Note>Returns the XSXML version currently in use.</Note>
    </Function>

    <Function id="28">
      <Name>_XMLError</Name>
      <Parameter id="1">
        <Name>sError</Name>
        <Default></Default>
      </Parameter>
      <Note>Sets or Gets XML error message generated by XML functions.</Note>
    </Function>

    <Function id="29">
      <Name>_XMLUDFVersion</Name>
      <Note>Returns the UDF Version number.</Note>
    </Function>

    <Function id="30">
      <Name>_XMLTransform</Name>
      <Parameter id="1">
        <Name>oXMLDoc</Name>
        <Default></Default>
        <Reference></Reference>
      </Parameter>
      <Parameter id="2">
        <Name>Style</Name>
        <Default></Default>
      </Parameter>
      <Parameter id="3">
        <Name>szNewDoc</Name>
        <Default></Default>
      </Parameter>
      <Note>Transfroms the document using built-in sheet or xsl file passed to function.</Note>
    </Function>

    <Function id="31">
      <Name>_XMLNodeExists</Name>
      <Parameter id="1">
        <Name>strXPath</Name>
      </Parameter>
      <Note>Checks for the existence of the specified path.</Note>
    </Function>
  </File>
</Project>

Edit: fixed a couple of id's, and other silly things.

An empty <Default> tag would usually denoted as <Default/> which is equivalent to <Default></Default>
Posted

i have a google map api tracking system im building, and i have a script that will get long and lat positions from a gps and phrases them then puts them into $long and $lat

my question is how can i write the following to a xml file with the var values

<markers>

<marker lat="$lat" lng="$long" speed="$speed" label="$title"/>

<infowindow>webcam screenshot</infowindow>

</markers>

or is there an easier way to do this with a static xml file already provided then the xml dom can just go in and update the $long and $lat value without having to write to the whole file again, because this also is going to get uploaded to ftp every 5-15 sec, maybe i can find a way to just send the $lat $long data to the remote servers xml file and like inject it, this way to save time and data transfer speed.

whats my best bet or best approach to what im trying to do?

Posted

i have a google map api tracking system im building, and i have a script that will get long and lat positions from a gps and phrases them then puts them into $long and $lat

my question is how can i write the following to a xml file with the var values

<markers>

<marker lat="$lat" lng="$long" speed="$speed" label="$title"/>

<infowindow>webcam screenshot</infowindow>

</markers>

or is there an easier way to do this with a static xml file already provided then the xml dom can just go in and update the $long and $lat value without having to write to the whole file again, because this also is going to get uploaded to ftp every 5-15 sec, maybe i can find a way to just send the $lat $long data to the remote servers xml file and like inject it, this way to save time and data transfer speed.

whats my best bet or best approach to what im trying to do?

I not sure how to approach this. I have a couple of questions. What is the minimal xml that the server needs in the xml file. Secondly is the file overwritten/modified or is a new file created with each ftp update.

If the xml file is not much more than the file above and you can overwrite the file, then the simplest approach in my opinion would be to create the file using regular file IO functions.

Local $lat="35.13N",$long="106.64W",$speed="10",$title="Albuquerque NM" ; get these values from gps
Local $outfile = "gps.xml" ;set the output filename

Local $exitCode = 0
;setup the xml string
Local $xmlContent = "" & _
'<?xml version="1.0" encoding="UTF-16"?>\n' & _
'<markers>\n' & _
' <marker lat="%s" lng="%s" speed="%s" label="%s"/>\n' & _
'   <infowindow>webcam screenshot</infowindow>\n' & _
'</markers>\n'

Local $fho = FileOpen($outfile,(32+2)) ;utf-16 little endian with overwrite
    If @error Then 
        MsgBox(266288,"Error","Could not open the file "&$outfile&" for writing")
        Exit 1
    EndIf
    FileWrite($fho,StringFormat($xmlContent,$lat,$long,$speed,$title))
    If @error Then
        MsgBox(266288,"Error","An error occured while writting to the file: "&$outfile)
        $exitCode = 1
    EndIf
FileClose($fho)
Exit($exitCode)

I'm not sure how one would "inject" the xml on the server.

Posted

HELLO All,

looking on all examples i still didn't get the basic idea how to work with the XML DOM wrapper since i am not familiar with XML and new to Autoit.

i have an xml i would like to retrieve all TestingMode values ,i f someone could post example will be most helpful

Thanks in advanced

<NetworTest>
<TestingMode Name="IperfTesting">
    <TestInfra Name="1GigaNet">
        <TemplateTitle Name="1GIGA Net 1ms or less">
            <CLIrun>-f -r-s -s</CLIrun>
        </TemplateTitle>
        <TemplateTitle Name="1GIGA Net 10ms or less">
            <CLIrun>-f -r-s -s</CLIrun>
        </TemplateTitle>
    </TestInfra>
</TestingMode>

<TestingMode Name="Netperf Testing">
    <TestInfra Name="1GigaNet">
        <TemplateTitle Name="1GIGA Net 1ms or less">
            <CLIrun>-f -r-s -s</CLIrun>
        </TemplateTitle>
        <TemplateTitle Name="1GIGA Net 10ms or less">
            <CLIrun>-f -r-s -s</CLIrun>
        </TemplateTitle>
    </TestInfra>
</TestingMode>
</NetworTest>
Posted

@tbaror

#include <_XMLDomWrapper.au3>
#include <Array.au3>

;XML file to open
$sXMLFile = "TemplateData.xml"

$result = _XMLFileOpen($sXMLFile)
if $result = 0 then Exit

$rootPath = '/NetworTest'

;Write all TestingMode names to console (Attributes are case sensitive)
$TestingModeArray = _XMLGetChildNodes($rootPath)
For $W = 1 to $TestingModeArray[0]
    $WNode = $TestingModeArray[$W]
    $TestingModePath = $rootPath & "/" & $WNode & "[" & $W & "]"
    ConsoleWrite($WNode & ": " & _XMLGetAttrib ($TestingModePath, "Name") & @CRLF)    
    
    
    ;Write all TestInfra names to console (Attributes are case sensitive)
    $TestInfraArray = _XMLGetChildNodes($TestingModePath)
    For $X = 1 to $TestInfraArray[0]
        $XNode = $TestInfraArray[$X]
        $TestInfraPath = $TestingModePath & "/" & $XNode & "[" & $X & "]"
        ConsoleWrite(@TAB & $XNode & ": " & _XMLGetAttrib ($TestInfraPath, "Name") & @CRLF)

        ;Write all TemplateTitle names to console (Attributes are case sensitive)
        $TemplateTitleArray = _XMLGetChildNodes($TestInfraPath)
        For $Y = 1 to $TemplateTitleArray[0]
            $YNode = $TemplateTitleArray[$Y]
            $TemplateTitlePath = $TestInfraPath & "/" & $YNode & "[" & $Y & "]"
            ConsoleWrite(@TAB & @TAB & $YNode & ": " & _XMLGetAttrib ($TemplateTitlePath, "Name") & @CRLF)
            
            ;Write all TemplateTitle subnode values to console (Attributes are case sensitive)
            $TemplateTitleSubnodeArray = _XMLGetChildNodes($TemplateTitlePath)
            For $Z = 1 to $TemplateTitleSubnodeArray[0]
                $ZNode = $TemplateTitleSubnodeArray[$Z]
                $TemplateTitleSubnodePath = $TemplateTitlePath & "/" & $ZNode & "[" & $Z & "]"
                ConsoleWrite(@TAB & @TAB & @TAB & $ZNode & ": " & _GetFirstValue($TemplateTitleSubnodePath) & @CRLF)
            Next
        Next
    Next
Next


;Get the first real value returned from the _XMLGetValue() return array. REQUIRED
Func _GetFirstValue($node)
    $ret_val = _XMLGetValue($node)
    If IsArray($ret_val) Then
        Return ($ret_val[1])
    Else
        Return SetError(1,3,0)
    EndIf
EndFunc
Posted

I was gonna ask whether you wanted all the attribute values or just the value of CLIRun, but weaponx has it all sewn up. :)

Posted

@tbaror

#include <_XMLDomWrapper.au3>
#include <Array.au3>

;XML file to open
$sXMLFile = "TemplateData.xml"

$result = _XMLFileOpen($sXMLFile)
if $result = 0 then Exit

$rootPath = '/NetworTest'

;Write all TestingMode names to console (Attributes are case sensitive)
$TestingModeArray = _XMLGetChildNodes($rootPath)
For $W = 1 to $TestingModeArray[0]
    $WNode = $TestingModeArray[$W]
    $TestingModePath = $rootPath & "/" & $WNode & "[" & $W & "]"
    ConsoleWrite($WNode & ": " & _XMLGetAttrib ($TestingModePath, "Name") & @CRLF)    
    
    
    ;Write all TestInfra names to console (Attributes are case sensitive)
    $TestInfraArray = _XMLGetChildNodes($TestingModePath)
    For $X = 1 to $TestInfraArray[0]
        $XNode = $TestInfraArray[$X]
        $TestInfraPath = $TestingModePath & "/" & $XNode & "[" & $X & "]"
        ConsoleWrite(@TAB & $XNode & ": " & _XMLGetAttrib ($TestInfraPath, "Name") & @CRLF)

        ;Write all TemplateTitle names to console (Attributes are case sensitive)
        $TemplateTitleArray = _XMLGetChildNodes($TestInfraPath)
        For $Y = 1 to $TemplateTitleArray[0]
            $YNode = $TemplateTitleArray[$Y]
            $TemplateTitlePath = $TestInfraPath & "/" & $YNode & "[" & $Y & "]"
            ConsoleWrite(@TAB & @TAB & $YNode & ": " & _XMLGetAttrib ($TemplateTitlePath, "Name") & @CRLF)
            
            ;Write all TemplateTitle subnode values to console (Attributes are case sensitive)
            $TemplateTitleSubnodeArray = _XMLGetChildNodes($TemplateTitlePath)
            For $Z = 1 to $TemplateTitleSubnodeArray[0]
                $ZNode = $TemplateTitleSubnodeArray[$Z]
                $TemplateTitleSubnodePath = $TemplateTitlePath & "/" & $ZNode & "[" & $Z & "]"
                ConsoleWrite(@TAB & @TAB & @TAB & $ZNode & ": " & _GetFirstValue($TemplateTitleSubnodePath) & @CRLF)
            Next
        Next
    Next
Next


;Get the first real value returned from the _XMLGetValue() return array. REQUIRED
Func _GetFirstValue($node)
    $ret_val = _XMLGetValue($node)
    If IsArray($ret_val) Then
        Return ($ret_val[1])
    Else
        Return SetError(1,3,0)
    EndIf
EndFunc
i really appreciate it thank you thank you :)
Posted

Hi, I ran the _XMLExample.au3 on windows vista ultimate and I got an error on lin 199 (Variable must be of type Object)

Is this a bug on the example file or it is some kind of incompatibility on Windows Vista OS?

Thanks in advance

Posted

Hi, I ran the _XMLExample.au3 on windows vista ultimate and I got an error on lin 199 (Variable must be of type Object)

Is this a bug on the example file or it is some kind of incompatibility on Windows Vista OS?

Thanks in advance

That was a bug in the example file that is now fixed.

Thanks! GioVit.

  • 2 weeks later...
Posted

it seems the code is not able to create an array of elements if you use xpath. will let you know when i have sorted it

If you fool around with a thing for very long you will screw it up
Posted

This is an old post, but i guess i might s well respond. This is how i sorted the problem

$oXml = ObjCreate("MSXML2.DOMdocument.4.0")

$oXml.async = False

$oXml.Load("main_data.xml")

$oXml.setProperty ("SelectionLanguage", "XPath")

$nodes = _XMLSelectNodes("/my-data/image[pid='0']")

If $nodes <> -1 Then

For $node In $nodes

debug($node.getAttribute("pid"))

Next

EndIf

Func _XMLSelectNodes($strXPath)

If not IsObj($oXml) Then Return -1

$nodeList = $oXml.selectNodes ($strXPath)

If Not IsObj($nodeList)Or $nodeList.length < 1 Then Return -1

Return $nodeList

EndFunc

Func debug($text)

MsgBox(0,'debug',$text)

EndFunc

and my xml file looks like this

<?xml version="1.0" encoding="UTF-8" ?>

<my-data>

<image id="1" link="A1.htm" src="A1.jpg" pid="1"><pid>0</pid></image>

<image id="2" link="A2.htm" src="A2.jpg" pid="2"><pid>0</pid></image>

<image id="3" link="A3.htm" src="A3.jpg" pid="3"><pid>0</pid></image>

<image id="4" link="A4.htm" src="A4.jpg" pid="4"><pid>0</pid></image>

<image id="5" link="A5.htm" src="A5.jpg" pid="5"><pid>0</pid></image>

</my-data>

funny but if i remove the last element <pid>0</pid> it wont work. i wonder why... :)

If you fool around with a thing for very long you will screw it up
  • 3 weeks later...
Posted

HI!

I'm trying to read out some special XML file, is it possible too and if yes how:

code .au3:

_XMLFileOpen($path)
Msgbox(0, "", _XMLGetValue("mod/title"))

the file looks like this:

<mod>
    <title> Conflict 2142 </title>
    <desc>Welcome to Conflict 2142 a premier tournament. Where you the player decides how our mod works. How our maps are made. You the player is what makes it happen. Make sure to get the latest at www.conflict2142.com and become a soldier of the future. Sponsered by v i p e r tournaments.
 </desc>
    <url> http://www.Conflict2142.com</url>
    <logo> mod.png </logo>
    <icon> mod_icon.png </icon>
    <music> sound/music/Menu.ogg </music> 
    <version> 2.0 </version>
</mod>

I want to get the "title" information.

Thanks!

Posted

Ok, found it out by

XMLFileOpen($bf2installdirection & "\mods\" & $bf2mods & "\mod.desc")
$modtitle = _XMLGetChildText("mod/title")

I want to open several files to read the titles out, so I need something like

XMLFileClose()

or equal.

What to do?

Posted

Ok, found it out by

XMLFileOpen($bf2installdirection & "\mods\" & $bf2mods & "\mod.desc")
 $modtitle = _XMLGetChildText("mod/title")

I want to open several files to read the titles out, so I need something like

XMLFileClose()

or equal.

What to do?

You have to use the MDI version from the first post. Each time you open an XML object it adds a handle to a global array. This lets you have multiple XML files open.
Posted

works with

#include <_XMLDomWrapper.au3>
_XMLFileOpen("C:\Programme\EA GAMES\Battlefield 2\mods\bf2\mod.desc")
$modtitle = _XMLGetChildText("mod/title")
Msgbox(0, "", $modtitle[1])
_XMLFileOpen("C:\Programme\EA GAMES\Battlefield 2142\mods\bf2142\mod.desc")
$modtitle = _XMLGetChildText("mod/title")
Msgbox(0, "", $modtitle[1])

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...