[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Simple API for accessing data in an XML file in Java ? without ha vingto
I would like to use something simple 'like' the Microsoft ADO record set object (a cursor that enables to retrieve and update very simply from/to an XML file). I am not a Microsoft developer, yet was shown that and was quite impressed by the simplicity of that API and wondering if there is any equivalent in Java. This is a dramatic simplification of things especially in an application that constantly need to read and write to such a file. (Possibly for hundreds of attributes) Since I don't need to build relations between nodes or to express any model/relations in my XML file and don't want to traverse enumerations (DOM) or use events (SAX) to get and set a s-i-n-g-l-e value (big overhead .. the parsing ) . I don't need in this particular case to write all the parsing (overkill) The Microsoft implementation allows to filter by attribute or combination of attributes (equivalent of a SQL where clause). If there is no API I may have to resort to using a cached properties file or store the whole thing in a database and cache it. Thanks Ari Here is an example of the ASP and XML file that stores the data set oRSXML = server.CreateObject("adodb.recordset") oRSXML.CursorLocation = adUseClient oRSXML.CacheSize = 100 .... .... function GetXMLElement(oRSXML, sElementName) 'this function searches oRSXML for the first occurence of the sElementName parameter 'if the element is found then the text value associated with the element is returned 'on error resume next dim sElement oRSXML.movefirst oRSXML.find("ElementName = '" & sElementName & "'") if err <> 0 or oRSXML.bof or oRSXML.eof then GetXMLElement = "" else GetXMLElement = oRSXML("value") end if end function <xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882' xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882' xmlns:rs='urn:schemas-microsoft-com:rowset' xmlns:z='#RowsetSchema'> <s:Schema id='RowsetSchema'> <s:ElementType name='row' content='eltOnly' rs:updatable='true'> <s:AttributeType name='ElementName' rs:number='1' rs:write='true'> <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='50' rs:precision='0' rs:maybenull='false'/> </s:AttributeType> <s:AttributeType name='Desc' rs:number='2' rs:write='true'> <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='50' rs:precision='0' rs:maybenull='false'/> </s:AttributeType> <s:AttributeType name='PageName' rs:number='3' rs:write='true'> <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='50' rs:precision='0' rs:maybenull='false'/> </s:AttributeType> <s:AttributeType name='SectionName' rs:number='4' rs:write='true'> <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='50' rs:precision='0' rs:maybenull='false'/> </s:AttributeType> <s:AttributeType name='Value' rs:number='5' rs:write='true'> <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='1024' rs:precision='0' rs:maybenull='false'/> </s:AttributeType> <s:AttributeType name='Title' rs:number='6' rs:write='true'> <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='50' rs:precision='0' rs:maybenull='false'/> </s:AttributeType> <s:extends type='rs:rowbase'/> </s:ElementType> </s:Schema> <rs:data> <z:row ElementName='NumberMonthsFree' Desc='Number Months' PageName='Admin2' SectionName='NumberMonths' Value='2' Title=''/> <z:row ElementName='TopImageFile' Desc='Top Navbar Image ' PageName='Frame' SectionName='Image' Value='GMP_22222222_003_01.gif' Title=''/> <z:row ElementName='BottomImageFile' Desc='Bottom Navbar Image ' PageName='Frame' SectionName='Image' Value='GMP_22222222_000_06.gif' Title=''/> </rs:data> </xml>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|