Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Stefan, I am so sorry for missing this question (just found it by accident via Google while I was searching for something else).</p> <p>There are a few points of confusion here, so let me clarify, and then outline how I would recommend solving this (assuming you didn't find a way, but I realize this was 3 months ago)</p> <p>First, you are correct, you need a combination of CHARACTER rules and ATTRIBUTE rules. The CHARACTER rules will give you the content <em>between</em> tags, for example:</p> <pre><code>&lt;tag&gt;this is CHARACTER data&lt;/tag&gt; </code></pre> <p>Second, your rules should target tags that contain data you need, in your example above, it looks like you don't get any differentiating data until you get to the /data/article/field level (individual fields contain both ATTRIBUTES and CHARACTERS that you want)</p> <p>It <em>does</em> looks like you key off of (open tags) to tell when you have entered a new article so you know you are collecting field information for a specific, unique article. In that case you can actually use TAG rules to file when you hit a start tag, so you can do some logic like creating a new record in your HashMap for the soon-to-be-parsed new article.</p> <p>Lastly, the <em>Category</em> argument you have being passed to the handlers is a <em>pass-through</em> user-variable.</p> <p>What that means is you can call the Parse method:</p> <pre><code>XMLParser&lt;List&lt;Article&gt;&gt; p = new XMLParser&lt;List&lt;Article&gt;&gt;(... stuff ...); List&lt;Article&gt; articleList = new ArrayList&lt;Article&gt;(); p.parse(input, articleList); </code></pre> <p>this allows ALL your handlers to have direct access to your articleList so they can parse/store information directly in it, so when the call to parse(...) returns, you know your list is current and updated.</p> <p>If you do not pass anything to the parse method in the userObject field, then the handlers will all receive a <em>null</em> argument.</p> <p>Your use checking for <em>Category</em> had me confused and made me think you were expecting to get a changing value there when the handlers were called, which isn't the case. I just wanted to clarify that.</p> <p><strong>Summary</strong></p> <p>I think your perfect parser design would include 3 rules:</p> <ul> <li>/data/article TAG rule -- do something when a START article tag is encountered (and optionally when a CLOSE article tag is).</li> <li>/data/article/field CHARACTER rule -- store the parsed character data for the field.</li> <li>/data/article/field ATTRIBUTE rule -- store the parsed attribute data for the field.</li> </ul> <p>I hope that helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload