Jump to content

XML.au3 read XML structure


 Share

Recommended Posts

Hello together,

I have the following problem:

there is a given XML file.

structure is like this:

<A>
	<x i="2">data</x>
	<x i="3">data1</x>
	<x i="12">data3</x>
	<x i="28">
      <abc>
          <x i="0">subdata</x>
          <x i="1">subdata1</x>
      </abc>
	</x>
    <x i="30">
      <def>
          <x i="0">
          	<sub>
            	<x i= "0">sub1</x>
            	<x i= "1">sub2</x>
            	<x i= "2">sub3</x>
        	</sub>
          </x>
          
          <x i="1">subdata123</x>
      </def>
   </x>
</A>
    	
    

if the node contains only a number or text, the _XML_GetValue gives the correct answer. I use this code:
 

$wert =_XML_GetValue($oXMLDoc, '/A/x[@i=' & $j & ']')

If the node contains a sub-XML structure the return is empty.

How can I reach the sub structure? No, I can not change the structure, this is given.

Any help?
Many thanks in advance.

---------------------------------------
best regards
Frank

Link to comment
Share on other sites

You can do this, if you just want to loop through every /x:

//x

or this would give the same results

/A//x

2 slashes means you go as deep as you can find a match.

 

Edit: I'd recommend looking for /A/x...and then use that return object to see if there was text data...if not, then look for child nodes of that object.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

is there the possibility to get the value of a node as XML-structured string? like a part of the original XML-File?

is anywhere a list of the properties of a node ( .Text, .value and so...)

I got it.... there is a property .xml...
But: it returns only the first Child...
 

<p i=3>
    <xxxxxx>
        <p i=0>abcdef</p>
        <p i=2>asdfh</p>
    </xxxxxx>
    <xxxxxx>
        <p i=0>zzz</p>
        <p i=2>aspouuioudfh</p>
    </xxxxxx>
</p>

there is only

<xxxxxx><p i=0>abcdef</p><p i=2>asdfh</p></xxxxxx>

reported instead of
 

<xxxxxx><p i=0>abcdef</p><p i=2>asdfh</p></xxxxxx><xxxxxx><p i=0>zzz</p><p i=2>aspouuioudfh</p></xxxxxx>

the code:

$wert =_XML_GetValue_XML($oXMLDoc, '/P[@i=3]')

Func _XML_GetValue_XML(ByRef $oXmlDoc, $sXPath)
    ; Error handler, automatic cleanup at end of function
    Local $oXML_COM_ErrorHandler = ObjEvent("AutoIt.Error", __XML_ComErrorHandler_InternalFunction)
    #forceref $oXML_COM_ErrorHandler

    Local $oNode_Selected = _XML_SelectSingleNode($oXmlDoc, $sXPath)
    If @error Then
        Return SetError(@error, @extended, $XML_RET_FAILURE)
    ElseIf $oNode_Selected.hasChildNodes() Then
        Local $aResponse[1] = [0]
        For $oNode_enum_Child In $oNode_Selected.childNodes()
            If $oNode_enum_Child.nodeType = $XML_NODE_ELEMENT Then
                _XML_Array_AddName($aResponse, $oNode_enum_Child.xml)
;~          ElseIf $oNode_enum_Child.nodeType = $XML_NODE_TEXT Then
;~              _XML_Array_AddName($aResponse, $oNode_enum_Child.text)
            EndIf
        Next

        $aResponse[0] = UBound($aResponse) - 1
        Return SetError($XML_ERR_SUCCESS, $aResponse[0], $aResponse) ; TODO Description for @extended
    EndIf

    Return SetError($XML_ERR_NOCHILDMATCH, $XML_EXT_DEFAULT, $XML_RET_FAILURE)
EndFunc   ;==>_XML_GetValue_XML

Any hints?

the problem seems to be the same names of the subnodes...(<xxxxxx>). but this is given and not changeable.

Edited by GeosShark

---------------------------------------
best regards
Frank

Link to comment
Share on other sites

.xml returns only the node details, and it's children.  You are referring to a 'sibling', which on the same level.  So you would need to select all, and then loop through the return.  I'm not familiar with the xml functions you are using, but instead of _XML_SelectSingleNode, there should be something like $oNodes = _XML_selectnodes.

When you get the return, you can for a 'For $oNode in $oNodes' and loop through that to get the .text, or .xml, or .getattribute(), or whatever.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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