문제

In my project, I have to create a XML file from my IndexedDB datas. I am passing that XML file to my WebService that will save my datas to my Server.. And in return, I also want to read and parse XML file (or data) sent by my WebService.. So give me some suggestions..

도움이 되었습니까?

해결책 2

Why don't you write a REST service. This will interface a lot easier with the indexeddb. On the service you can parse the json data into objects you can save into the database.

다른 팁

IDB "object stores" can only store JavaScript objects. To save XML data to an IDB database you'll need to transform the XML object into a JavaScript object. That function will depend on your XML needs - there's no one-size-fits-all approach to XML transformation.

In general, follow the advice I laid out for you here in translating your XML objects into a JSON representation:

For example, if your SQL table looked like this:

+------+--------+--------+
|      | ColA   | ColB   |
+------+--------+--------+
| Row1 | CellA1 | CellB1 |
| Row2 | CellA2 | CellB2 |
| Row3 | CellA3 | CellB3 |
+------+--------+--------+

Your JavaScript object may look like this:

var myObjectToStore = {
    'Row1': { 'ColA': 'CellA1', 'ColB': 'CellB1' },
    'Row2': { 'ColA': 'CellA2', 'ColB': 'CellB2' },
    'Row3': { 'ColA': 'CellA3', 'ColB': 'CellB3' }
};

The JSON representation of that object is very similar:

{
  "Row1": {
    "ColA": "CellA1",
    "ColB": "CellB1"
  },
  "Row2": {
    "ColA": "CellA2",
    "ColB": "CellB2"
  },
  "Row3": {
    "ColA": "CellA3",
    "ColB": "CellB3"
  }
}

It's far easier to use JavaScript objects without such serialization. I would highly suggest exploring using JSON over the network rather than XML.

Modern browsers all support JSON.parse() and JSON.stringify and most web servers can handle the application/json mimetype.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top