Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use variables in XML files?

Tags:

xml

Is it possible to define variables in an XML file?

For example:

VARIABLE = 'CHIEF_NAME'

    <foods>
      <food>
        <name>French Toast</name>
        <price>$4.50</price>
        <calories>600</calories>
        <chief>VARIABLE</chief>
      </food>
      <food>
        <name>Homestyle Breakfast</name>
        <price>$6.95</price>
        <calories>950</calories>
        <chief>VARIABLE</chief>
      </food>
    </foods>
like image 862
cbr Avatar asked Jan 13 '16 21:01

cbr


People also ask

How can I get dynamic value in XML?

You can use the format string method. You can specify the positional/keyword arguments in your xml file. While making the requests call, you can pass the values for those arguments.

What should every XML file contain?

All XML documents must contain a single tag pair to define a root element. All other elements must be within this root element. All elements can have sub elements (child elements). Sub elements must be correctly nested within their parent element.

What can XML files be used for?

XML (Extensible Markup Language) is used to describe data. The XML standard is a flexible way to create information formats and electronically share structured data via the public internet, as well as via corporate networks.


1 Answers

You can declare an entity reference for chief and reference it as &chief;:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE foods [
  <!ENTITY chief "CHIEF_NAME!">
  <!-- .... -->
]>
<foods>
  <food>
    <name>French Toast</name>
    <price>$4.50</price>
    <calories>600</calories>
    <chief>&chief;</chief>
  </food>
  <food>
    <name>Homestyle Breakfast</name>
    <price>$6.95</price>
    <calories>950</calories>
    <chief>&chief;</chief>
  </food>
</foods>
like image 136
kjhughes Avatar answered Oct 09 '22 18:10

kjhughes