dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Searching XML Docs

  1. #1
    Senior Member
    Join Date
    May 2003
    Posts
    160

    Searching XML Docs

    Ok I have an XML doc ... want I want to do is ... search though it and pull out certin nodes (I guess you call them that) if the search comes back true ...

    example ... I search for "NJ" I want to display all corresponding nodes with NJ ...

    Below is the XML doc
    PHP Code:
    <?xml version="1.0" encoding="UTF-8"?>

    <classes>

    <class state="NJ">
    <text desc="Text"></text>
    </class>

    <class state="CA">
    <text desc="Text"></text>
    </class>

    <class state="NJ">
    <text desc="Text"></text>
    </class>

    </classes>
    don't mind class and classes it will be named something else

    I want to search by state ... if thats possible

    thanks

    - s

  2. #2
    Member
    Join Date
    Jan 2003
    Location
    Australia, Adelaide (SA)
    Posts
    97
    Hi stvsfx,

    Try something like this:
    code:

    var xmlDoc = new XML();
    // ... load XML, and then sometime later ...

    var strState = "NJ";
    var arrResults = xmlDoc.firstChild.selectNodesByAttribute('state', strState);
    for( var i=0; i < arrResults.length; i++ )
    {
    trace( arrResults[i] );
    }

    XMLNode.prototype.selectNodesByAttribute = function( strAttributeName, strAttributeValue )
    {
    var arrNodes = new Array();
    for( var i=0; i < this.childNodes.length; i++ )
    {
    if( this.childNodes[i].nodeType == 1 &&
    this.childNodes[i].attributes[ strAttributeName ] == strAttributeValue )
    {
    arrNodes.push( this.childNodes[i] );
    }
    }
    return arrNodes;
    }


    I haven't had a chance to test it (don't have Flash here), but it should work.

    Hope this helps!
    Last edited by XMLEvangelist; 09-15-2003 at 09:42 PM.
    Tim Walters
    Senior Developer
    XML Evangelist
    "XML isn't a language, it's a way of life!"

  3. #3
    Senior Member
    Join Date
    May 2003
    Posts
    160
    THanks man .... I will give that a try ...

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center