Question: I have a problem with creating GlobalVariables for my webform app.
I am creating a webform app with Visual Studio 2015, VB.net, ASP.net
I followed the instruction that I found on this and other sites but with no successs.
I did the folowwing:

1 Create the module file: Module1.vb
With this scripts:

Public Module GlobalVariables2
 Public ModuleEMAIL As String = "ModuleEMAIL@zzzzzzzz"
End Module

Public Class GlobalVariables
 Public Shared Property clasEMAIL As String = "clasEMAIL@zzzzzzzz"
End Class

2. But when ever I try to call the variables a compiler error occur.

Function fnBtnText()
 Button1.Text = GlobalVariables.clasEMAIL
' generate: Compiler Error Message: BC30451: 'GlobalVariables' is not declared. It may be inaccessible due to its protection level.

```
          Button2.Text = ModuleEMAIL

```

'generate: Compiler Error Message: BC30451: 'ModuleEMAIL' is not declared. It may be inaccessible due to its protection level.
 End Function

What meas “protection level” in this case?
When the scripts are moved tot another spacename area the same happens.
What am I doing wrong? Did I missed something?
I hope someone van help me out.
Many greatigs, Ton Daamen

Answer: 
I am adding an [XMLWriter](http://php.net/XmlWriter) solution as an alternative.

XmlWriter can be a faster and less memory intensive solution over DOM or SimpleXml because it uses streams instead of holding the entire xml tree in memory.

Like mentioned elsewhere, you don't want `<item0>`, `<item1>` but instead use an ID attribute. [XML provides this via the xml:id attribute](https://www.w3.org/TR/xml-id/). The code below makes use of this.

I am using an [SplFileObject](http://php.net/manual/en/class.splfileobject.php) because it is a convenient file wrapper implementing the [Iterator interface and providing CSV control](https://stackoverflow.com/questions/2805427/how-to-extract-data-from-csv-file-in-php/2805486#2805486).

```
<?php

$reader = new SplFileObject('file/dat.txt');
$reader->setFlags(
    SplFileObject::READ_CSV |
    SplFileObject::DROP_NEW_LINE |
    SplFileObject::READ_AHEAD |
    SplFileObject::SKIP_EMPTY
);
$reader->setCsvControl('|');

$writer = new XMLWriter;
$writer->openURI('file/dat.xml'); // write to this file
$writer->setIndent(true);         // format the output
$writer->startDocument('1.0', 'UTF-8');
$writer->startElement("user");    // the root element

foreach ($reader as $row_data) {
    $row = array_map('trim', $row_data);
    $writer->startElement('item');
    $writer->writeAttributeNS('xml', 'id', null, $reader->key());
    $writer->writeElement("name", $row_data[0] ?? null);
    $writer->writeElement("email", $row_data[1] ?? null);
    $writer->writeElement("mobile", $row_data[2] ?? null);
    $writer->writeElement("address", $row_data[3] ?? null);
    $writer->endElement();
    $writer->flush();
}

$writer->fullEndElement();
$writer->endDocument();

```

Note that this requires PHP7 due to the use of the [null coalesce operator](https://wiki.php.net/rfc/isset_ternary) when writing the elements. If you are not on 7 yet, either update or use the old `isset`/`empty` constructs.
Using SimpleXML, you can build up the hierarchy of the XML document using...

```
    $data = 'Rajeet Singh|email@gmail.com|0123456789|Delhi  
    Abhishek|email2@gmail.com|0123456987|Pune';

    $lines = explode(PHP_EOL, $data);
    $xml = new SimpleXMLElement('<user />');
    $root = $xml->user;
    foreach($lines as $line){
        $data = explode("|",$line);
        $user = $xml->addChild('item');
        $user->addChild('name', $data[0]);
        $user->addChild('email', $data[1]);
        $user->addChild('mobile', $data[2]);
        $user->addChild('address', $data[3]);
    }

    echo $xml->asXML();

```

One thing which I don't do is create elements with a numeric postfix, you wouldn't normally (in XML) have elements `item0`, `item1` as this means they are different element types. You wold simply have them all as `item`. If you needed an index, you could create them with `item id="0"` so the id becomes the identifier (for example the unique ID of a database).