Note that there are some explanatory texts on larger screens.

plurals
  1. POQuestion Regarding XML Parsing Using SAX in JAVA
    primarykey
    data
    text
    <p>I am trying to parse an XML document in Java (first time attempting to do so), and I have found a number of articles on Google that provide examples but I really don't understand some of the code in them, so I was wondering if someone could explain a few things to me. The primary example I was looking at came from here: <a href="http://www.java-tips.org/java-se-tips/org.xml.sax/parsing-xml-with-a-simple-sax-document-handler-2.html/%22SAX%20Example%22" rel="nofollow">http://www.java-tips.org/java-se-tips/org.xml.sax/parsing-xml-with-a-simple-sax-document-handler-2.html</a>.</p> <p>My main questions primarily come from the second half of the code, specifically the part of...</p> <pre><code> // we enter to element 'qName': public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { if (qName.equals("purchase-order")) { } else if (qName.equals("date")) { } /* if (...) } */ else { throw new IllegalArgumentException("Element '" + qName + "' is not allowed here"); } } // we leave element 'qName' without any actions: public void endElement(String uri, String localName, String qName) throws SAXException { // do nothing; } </code></pre> <p>...could someone explain to me what exactly "String uri, String localName, String qName, and Attributes attrs are? I assume they are not code specific as I've seen them in a few examples. Also (assuming) that these are some sort of root elements in the XML file, could anyone provide some direction as to how I could use these to parse through the "document.xml.rels" file located within a .docx directory in a way that it would read and accept only the image files (not header, settings, etc) and their associated Relationship Id #'s? (Below is the short document I'm referring to)...</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes" ?&gt; - &lt;Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"&gt; &lt;Relationship Id="rId8" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer" Target="footer1.xml" /&gt; &lt;Relationship Id="rId13" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml" /&gt; &lt;Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml" /&gt; &lt;Relationship Id="rId7" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/header" Target="header1.xml" /&gt; &lt;Relationship Id="rId12" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable" Target="fontTable.xml" /&gt; &lt;Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml" /&gt; &lt;Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml" /&gt; &lt;Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes" Target="endnotes.xml" /&gt; &lt;Relationship Id="rId11" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/image3.png" /&gt; &lt;Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes" Target="footnotes.xml" /&gt; &lt;Relationship Id="rId10" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/image2.jpeg" /&gt; &lt;Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings" Target="webSettings.xml" /&gt; &lt;Relationship Id="rId9" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/image1.jpeg" /&gt; &lt;/Relationships&gt; </code></pre> <p>Thanks for any help in advance!</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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