Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is not the way you should parse an XML file, but since you don't want to use a parser library this code might get you started.</p> <p>File: <strong>demo.xml</strong></p> <pre><code>&lt;? xml version="1.0" ?&gt; &lt;fileStructure&gt; &lt;Main_Package&gt; File_Navigate &lt;/Main_Package&gt; &lt;Dependency_Details&gt; &lt;Dependency&gt; &lt;Package&gt; xmlMetadata &lt;/Package&gt; &lt;Header&gt; xmlMetadata.h &lt;/Header&gt; &lt;Header_path&gt; C:\Dependency\xmlMetadata\xmlMetadata.h &lt;/Header_path&gt; &lt;Implementation&gt; xmlMetadata.cpp &lt;/Implementation&gt; &lt;Implementation_path&gt; C:\Dependency\xmlMetadata\xmlMetadata.cpp &lt;/Implementation_path&gt; &lt;/Dependency&gt; &lt;Dependency&gt; &lt;Package&gt; xmlMetadata1 &lt;/Package&gt; &lt;Header&gt; xmlMetadata1.h &lt;/Header&gt; &lt;Header_path&gt; C:\Dependency\xmlMetadata\xmlMetadata1.h &lt;/Header_path&gt; &lt;Implementation&gt; xmlMetadata1.cpp &lt;/Implementation&gt; &lt;Implementation_path&gt; C:\Dependency\xmlMetadata\xmlMetadata1.cpp &lt;/Implementation_path&gt; &lt;/Dependency&gt; &lt;/Dependency_Details&gt; &lt;/fileStructure&gt; </code></pre> <p>The basic idea of the code is <em>while</em> you are reading each <em>line</em> of the file, strip the white spaces that are in the beginning and store the <em>new-stripped-string</em> into <em>tmp</em>, and then try to match it to one of the tags you are looking for. Once you find the <em>begin-tag</em>, keep printing the following lines until the <em>close-tag</em> is found.</p> <p>File: <strong>parse.cpp</strong></p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;fstream&gt; using namespace std; int main() { string line; ifstream in("demo.xml"); bool begin_tag = false; while (getline(in,line)) { std::string tmp; // strip whitespaces from the beginning for (int i = 0; i &lt; line.length(); i++) { if (line[i] == ' ' &amp;&amp; tmp.size() == 0) { } else { tmp += line[i]; } } //cout &lt;&lt; "--&gt;" &lt;&lt; tmp &lt;&lt; "&lt;--" &lt;&lt; endl; if (tmp == "&lt;Package&gt;") { //cout &lt;&lt; "Found &lt;Package&gt;" &lt;&lt; endl; begin_tag = true; continue; } else if (tmp == "&lt;/Package&gt;") { begin_tag = false; //cout &lt;&lt; "Found &lt;/Package&gt;" &lt;&lt; endl; } if (begin_tag) { cout &lt;&lt; tmp &lt;&lt; endl; } } } </code></pre> <p><strong>Outputs:</strong></p> <pre><code>xmlMetadata xmlMetadata1 </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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