×

Discussion Board

Results 1 to 3 of 3

Thread: xpath array

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    2

    Lightbulb xpath array

    Hello,

    have some XML parsing problem.

    In
    http://wiki.forum.nokia.com/index.ph...ith_XML_Filter

    it is described how to parse something like this:

    Code:
    <userdata>
    	<name>Sittiphol Phanvilai</name>
    	<namethai>สิทธิพล พรรณวิไล</namethai>
    	<address>
    		<city>Bangkok</city>
    		<state>-</state>
    		<country>Thailand</country>
    	</address>
    	<pet type="Dog" name="Richie"/>
    </userdata>
    But what can i do if i have a list?

    Code:
    <usertable>
    <userdata1>
    	<name>Sittiphol Phanvilai</name>
    	<xyz>sdsdsd</xyz>
    </userdata1>
    <userdata2>
    	<name>Sittiphol Phanvilai</name>
    	<xyz>sdsdsd</xyz>
    </userdata2>
    </usertable>

    I tried something like this but i didnt work:

    Code:
    <filters>
        <filter id="xpathfilter">
          <list>
            <foreach>
              <xpath>/usertable/*</xpath>
              <item>
                <name><xpath>name()</xpath></name>
                <value>
    				<list>
    					<foreach>
    					  <xpath>/magazin/*</xpath>
    					  <item>
    						<name><xpath>/usertable/*name()</xpath></name>
    						<value><xpath>/usertable/*text()</xpath></value>
    					  </item>
            		    </foreach>
          			</list>
    			</value>
              </item>
            </foreach>
          </list>
        </filter>
      </filters>
    It doesnt work :-(
    At the end i want to get this array:

    usertable(userdata1 => (name = "aaa", xyz = "sdsd"), userdata1 => (name = "aaa", xyz = "sdsd"));

    So that I can use: usertable[userdata1][name] ...

    I'm looking forward to a solution, worked 3 hours now and I'm very sad :-(

    Greetz Yuri

  2. #2
    Regular Contributor
    Join Date
    Jul 2004
    Posts
    52

    Smile Re: xpath array

    Hello, it should work like this:

    Code:
        <filter id="httpcontent">
          <list>
            <foreach>
              <xpath>/usertable/*</xpath>
              <list>
                <name><xpath>name()</xpath></name>
                <value>
                  <foreach>
                    <xpath>*</xpath>
                    <item>
                      <name><xpath>name()</xpath></name>
                      <value><xpath>text()</xpath></value>
                    </item>
                  </foreach>
                </value>
              </list>
            </foreach>
          </list>
        </filter>
    However due to bug in xpath-implementation name() will contain extra [] characters so you need to remove them either in the filter using xpath substring or regex, or in your script code ;(

    Personally I don't use xpath so often so whenever I need to use it I need to learn it again However I have used following sites as reference:
    http://www.w3schools.com/Xpath/
    http://www.dpawson.co.uk/xsl/sect2/sect21.html (this is really for xslt but still contains a lot of advanced xpath stuff)

    /render

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    2

    Re: xpath array

    Hey thanks, thats what I needed :-)

    Greetz from Germany

Similar Threads

  1. Grid app is crashing... need urgent help...
    By shankha in forum Symbian
    Replies: 5
    Last Post: 2010-10-19, 12:07
  2. corrupted array in namespace
    By jmpep in forum Symbian
    Replies: 2
    Last Post: 2008-11-02, 20:37
  3. sending a snapshot array byte to server
    By irene1986 in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2008-04-01, 21:52
  4. Replies: 5
    Last Post: 2006-02-26, 17:29
  5. Replies: 2
    Last Post: 2005-03-14, 15:22

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×